stride3d/stride · error · ArgumentNullException
Value cannot be null. (Parameter 'routedEvent')
Error message
Value cannot be null. (Parameter 'routedEvent')
What it means
Argument-null validation in UIElement.AddHandler: the routedEvent parameter is null. AddHandler stores the handler keyed by the RoutedEvent; without a valid event identifier the handler could never be matched during routing, so the call is rejected with ArgumentNullException named 'routedEvent'.
Solutions
- Pass the static RoutedEvent field (e.g. UIElement.SomeEventEvent) to AddHandler instead of a null reference.
- Ensure the RoutedEvent was registered via RoutedEvent.Register before any AddHandler call runs; check static-initialization order in partial/event definition classes.
- Guard call sites where the routed event reference is resolved dynamically and may be null.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at sources/engine/Stride.UI/UIElement.Events.cs:199 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/7242e836ac1df4bf.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.UI/UIElement.Events.cs:199
e.EndEventRouting();
if (sourceWasNull) // reset the source if it was not explicitly set (event might be reused again for other sources)
e.Source = null;
}
/// <summary>
/// Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element.
/// Specify handledEventsToo as true to have the provided handler be invoked for routed event that had already been marked as handled by another element along the event route.
/// </summary>
/// <param name="routedEvent">An identifier for the routed event to be handled.</param>
/// <param name="handler">A reference to the handler implementation.</param>
/// <param name="handledEventsToo">true to register the handler such that it is invoked even when the routed event is marked handled in its event data;
/// false to register the handler with the default condition that it will not be invoked if the routed event is already marked handled.</param>
/// <exception cref="ArgumentNullException">Provided handler or routed event is null.</exception>
public void AddHandler<T>(RoutedEvent<T> routedEvent, EventHandler<T> handler, bool handledEventsToo = false) where T : RoutedEventArgs
{
if (routedEvent == null) throw new ArgumentNullException(nameof(routedEvent));
if (handler == null) throw new ArgumentNullException(nameof(handler));
if (!eventsToHandlers.TryGetValue(routedEvent, out List<RoutedEventHandlerInfo> handlerInfos))
eventsToHandlers[routedEvent] = handlerInfos = new List<RoutedEventHandlerInfo>();
handlerInfos.Add(new RoutedEventHandlerInfo<T>(handler, handledEventsToo));
}
/// <summary>
/// Removes the specified routed event handler from this element.
/// </summary>
/// <param name="routedEvent">The identifier of the routed event for which the handler is attached.</param>
/// <param name="handler">The specific handler implementation to remove from the event handler collection on this element.</param>
/// <exception cref="ArgumentNullException">Provided handler or routed event is null.</exception>
public void RemoveHandler<T>(RoutedEvent<T> routedEvent, EventHandler<T> handler) where T : RoutedEventArgs
{
if (routedEvent == null) throw new ArgumentNullException(nameof(routedEvent));
if (handler == null) throw new ArgumentNullException(nameof(handler));View on GitHub (pinned to 96fad776d2)