dotnet/wpf · error · ArgumentException
SR.Format(SR.NullPropertyIllegal, "EventSetter.Event")
Error message
SR.Format(SR.NullPropertyIllegal, "EventSetter.Event")
What it means
EventSetter.Seal validates the setter before a Style/EventTrigger is finalized. It throws ArgumentException naming EventSetter.Event when the Event property (the RoutedEvent) is null, since an event setter must know which event to hook.
Solutions
- Set the Event property: <EventSetter Event="Button.Click" Handler="OnButtonClick"/>
- In code, assign setter.Event = ButtonBase.ClickEvent before the style is sealed
- Check style resources for EventSetter entries lacking an Event attribute
Example fix
// before
var es = new EventSetter { Handler = new RoutedEventHandler(OnClick) };
style.Setters.Add(es); // throws on Seal
// after
var es = new EventSetter { Event = ButtonBase.ClickEvent, Handler = new RoutedEventHandler(OnClick) };
style.Setters.Add(es); Defensive patterns
Strategy: validation
Validate before calling
if (eventSetter.Event == null) throw new InvalidOperationException("EventSetter.Event must be set before sealing the style"); Type guard
bool IsValidEventSetter(EventSetter s) => s?.Event != null;
Try / catch
try { style.Seal(); }
catch (ArgumentException ex) when (ex.Message.Contains("EventSetter.Event")) { fixSetter(); } Prevention
- Always set both Event and Handler on EventSetter
- Validate style setters before adding to shared styles
When it happens
Trigger: Adding an EventSetter to a Style's Setters without setting Event, then sealing the style (style is used / sealed implicitly).
Common situations: XAML like <EventSetter Handler="..."/> missing the Event attribute; code-built styles that forget style.Setters.Add with ev only partially configured.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- SR.Format(SR.NullPropertyIllegal, "EventSetter.Handler")
- SR.CannotHaveEventHandlersInThemeStyle
- SR.Format(SR.CannotHavePropertyInTemplate…
- SR.Format(SR.NullPropertyIllegal, "Setter.Property")
- SR.Format(SR.UnexpectedParameterType, value.GetType()…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8acf7df061047ba0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/EventSetter.cs:95
set
{
CheckSealed();
_handledEventsToo = value;
}
}
//
// Do the error checking that we can only do once all of the properties have been
// set, then call up to base.
//
internal override void Seal()
{
if (_event == null)
{
throw new ArgumentException(SR.Format(SR.NullPropertyIllegal, "EventSetter.Event"));
}
if (_handler == null)
{
throw new ArgumentException(SR.Format(SR.NullPropertyIllegal, "EventSetter.Handler"));
}
if (_handler.GetType() != _event.HandlerType)
{
throw new ArgumentException(SR.HandlerTypeIllegal);
}
base.Seal();
}
private RoutedEvent _event;
private Delegate _handler;
private bool _handledEventsToo;View on GitHub (pinned to 81131a70a4)