stride3d/stride · error · InvalidOperationException
The type of second parameter of the handler ({HandlerSecondA
Error message
The type of second parameter of the handler ({HandlerSecondArgumentType}) is not assignable from the parameter 'e' type ({e.GetType()}). What it means
Thrown by UIElement.RaiseEvent when the second parameter type of a registered handler is not assignable from the type of the RoutedEventArgs being raised. RaiseEvent uses reflection to invoke handlers with their expected strongly-typed event args; if a handler was registered for a different event-args type than the one being routed (e.g. handler expects TouchEventArgs but a plain RoutedEventArgs arrives), the invocation is invalid, so an InvalidOperationException naming both types is thrown.
Solutions
- Raise the event with a RoutedEventArgs-derived instance whose type matches the handler signature registered for that RoutedEvent (e.g. pass the derived args type the delegate's second parameter expects).
- Verify that the RoutedEvent was registered with the correct handler type and that the raised args type derives from HandlerSecondArgumentType.
- If args are pooled or reused across events, reset or recreate them with the correct concrete type before raising instead of reusing an incompatible instance.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at sources/engine/Stride.UI/UIElement.Events.cs:171 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/94e4e46a016842ba.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.UI/UIElement.Events.cs:171
}
/// <summary>
/// Raises a specific routed event. The <see cref="RoutedEvent"/> to be raised is identified within the <see cref="RoutedEventArgs"/> instance
/// that is provided (as the <see cref="RoutedEvent"/> property of that event data).
/// </summary>
/// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data and also identifies the event to raise.</param>
/// <exception cref="ArgumentNullException"><paramref name="e"/> is null.</exception>
/// <exception cref="InvalidOperationException">The type of the routed event argument <paramref name="e"/> does not match the event handler second argument type.</exception>
public void RaiseEvent(RoutedEventArgs e)
{
if (e == null)
throw new ArgumentNullException(nameof(e));
if (e.RoutedEvent == null)
return;
if (!e.RoutedEvent.HandlerSecondArgumentType.GetTypeInfo().IsAssignableFrom(e.GetType().GetTypeInfo()))
throw new InvalidOperationException("The type of second parameter of the handler (" + e.RoutedEvent.HandlerSecondArgumentType
+ ") is not assignable from the parameter 'e' type (" + e.GetType() + ").");
var sourceWasNull = e.Source == null;
if (sourceWasNull) // set the source to default if needed
e.Source = this;
e.StartEventRouting();
PropagateRoutedEvent(e);
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. View on GitHub (pinned to 96fad776d2)