{"record":{"id":"7242e836ac1df4bf","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-routedevent-uielement-events","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'routedEvent')","messagePattern":"Value cannot be null\\. \\(Parameter 'routedEvent'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.UI/UIElement.Events.cs","lineNumber":199,"sourceCode":"\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. \n        /// 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.\n        /// </summary>\n        /// <param name=\"routedEvent\">An identifier for the routed event to be handled.</param>\n        /// <param name=\"handler\">A reference to the handler implementation.</param>\n        /// <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; \n        /// false to register the handler with the default condition that it will not be invoked if the routed event is already marked handled.</param>\n        /// <exception cref=\"ArgumentNullException\">Provided handler or routed event is null.</exception>\n        public void AddHandler<T>(RoutedEvent<T> routedEvent, EventHandler<T> handler, bool handledEventsToo = false) where T : RoutedEventArgs\n        {\n            if (routedEvent == null) throw new ArgumentNullException(nameof(routedEvent));\n            if (handler == null) throw new ArgumentNullException(nameof(handler));\n\n            if (!eventsToHandlers.TryGetValue(routedEvent, out List<RoutedEventHandlerInfo> handlerInfos))\n                eventsToHandlers[routedEvent] = handlerInfos = new List<RoutedEventHandlerInfo>();\n\n            handlerInfos.Add(new RoutedEventHandlerInfo<T>(handler, handledEventsToo));\n        }\n\n        /// <summary>\n        /// Removes the specified routed event handler from this element.\n        /// </summary>\n        /// <param name=\"routedEvent\">The identifier of the routed event for which the handler is attached.</param>\n        /// <param name=\"handler\">The specific handler implementation to remove from the event handler collection on this element.</param>\n        /// <exception cref=\"ArgumentNullException\">Provided handler or routed event is null.</exception>\n        public void RemoveHandler<T>(RoutedEvent<T> routedEvent, EventHandler<T> handler) where T : RoutedEventArgs\n        {\n            if (routedEvent == null) throw new ArgumentNullException(nameof(routedEvent));\n            if (handler == null) throw new ArgumentNullException(nameof(handler));","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.UI/UIElement.Events.cs#L181-L217","documentation":"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'.","triggerScenarios":"Thrown at sources/engine/Stride.UI/UIElement.Events.cs:199 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"validation","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"}