{"record":{"id":"94e4e46a016842ba","repo":"stride3d/stride","slug":"the-type-of-second-parameter-of-the-handler","errorCode":null,"errorMessage":"The type of second parameter of the handler ({HandlerSecondArgumentType}) is not assignable from the parameter 'e' type ({e.GetType()}).","messagePattern":"The type of second parameter of the handler \\((.+?)\\) is not assignable from the parameter 'e' type \\((.+?)\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.UI/UIElement.Events.cs","lineNumber":171,"sourceCode":"        }\n\n        /// <summary>\n        /// Raises a specific routed event. The <see cref=\"RoutedEvent\"/> to be raised is identified within the <see cref=\"RoutedEventArgs\"/> instance \n        /// that is provided (as the <see cref=\"RoutedEvent\"/> property of that event data).\n        /// </summary>\n        /// <param name=\"e\">A <see cref=\"RoutedEventArgs\"/> that contains the event data and also identifies the event to raise.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"e\"/> is null.</exception>\n        /// <exception cref=\"InvalidOperationException\">The type of the routed event argument <paramref name=\"e\"/> does not match the event handler second argument type.</exception>\n        public void RaiseEvent(RoutedEventArgs e)\n        {\n            if (e == null)\n                throw new ArgumentNullException(nameof(e));\n\n            if (e.RoutedEvent == null)\n                return;\n\n            if (!e.RoutedEvent.HandlerSecondArgumentType.GetTypeInfo().IsAssignableFrom(e.GetType().GetTypeInfo()))\n                throw new InvalidOperationException(\"The type of second parameter of the handler (\" + e.RoutedEvent.HandlerSecondArgumentType\n                                                    + \") is not assignable from the parameter 'e' type (\" + e.GetType() + \").\");\n\n            var sourceWasNull = e.Source == null;\n            if (sourceWasNull) // set the source to default if needed\n                e.Source = this;\n\n            e.StartEventRouting();\n\n            PropagateRoutedEvent(e);\n\n            e.EndEventRouting();\n\n            if (sourceWasNull) // reset the source if it was not explicitly set (event might be reused again for other sources)\n                e.Source = null;\n        }\n\n        /// <summary>\n        /// Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. ","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.UI/UIElement.Events.cs#L153-L189","documentation":"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.","triggerScenarios":"Thrown at sources/engine/Stride.UI/UIElement.Events.cs:171 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}