{"record":{"id":"fbd05e04304c4da6","repo":"stride3d/stride","slug":"impossible-to-find-a-valid-event-named-eventname","errorCode":null,"errorMessage":"Impossible to find a valid event named '{EventName}'.","messagePattern":"Impossible to find a valid event named '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnEventBehavior.cs","lineNumber":88,"sourceCode":"\n            var uiElement = AssociatedObject as UIElement;\n\n            var routedEvents = EventManager.GetRoutedEvents().Where(x => x.Name == EventName && x.OwnerType.IsAssignableFrom(eventOwnerType)).ToArray();\n\n            if (uiElement != null && routedEvents.Length > 0)\n            {\n                if (routedEvents.Length > 1)\n                    throw new NotImplementedException(\"TODO: several events found, find a way to decide the most relevant one.\");\n\n                routedEvent = routedEvents.First();\n                uiElement.AddHandler(routedEvent, routedEventHandler);\n            }\n            else\n            {\n                var eventInfo = AssociatedObject.GetType().GetEvent(EventName);\n\n                if (eventInfo == null)\n                    throw new InvalidOperationException($\"Impossible to find a valid event named '{EventName}'.\");\n\n                eventHandler = AnonymousEventHandler.RegisterEventHandler(eventInfo, AssociatedObject, OnEvent);\n            }\n        }\n\n        /// <inheritdoc/>\n        protected override void OnDetaching()\n        {\n            if (routedEvent != null)\n            {\n                var uiElement = (UIElement)AssociatedObject;\n                uiElement.RemoveHandler(routedEvent, routedEventHandler);\n                routedEvent = null;\n            }\n            else if (eventHandler != null)\n            {\n                AnonymousEventHandler.UnregisterEventHandler(eventHandler);\n                eventHandler = null;","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnEventBehavior.cs#L70-L106","documentation":"OnEventBehavior.OnAttached throws InvalidOperationException when the event name could not be resolved as a routed event and the associated object's type exposes no CLR event with EventName. It means the behavior found no event at all to subscribe to. The message names the EventName that was searched.","triggerScenarios":"Setting EventName to a name that matches no routed event on the UIElement and no CLR event on AssociatedObject.GetType() — typically a typo or an event that does not exist on that control type.","commonSituations":"Typo in EventName (e.g. \"MouseLeftButonDown\"); EventName valid on a different control class than the one the behavior is attached to; control API changed across framework versions.","solutions":["Correct the EventName spelling to match an event that exists on the associated object.","Verify the event exists on the attached control's type via its documentation/reflection.","Set EventOwnerType if the event is an attached/routed event owned by another type.","Use x:Bind of snoop/inspect the live visual tree to confirm available event names."],"exampleFix":"// before\n<behaviors:OnEventBehavior EventName=\"MouseLeftButonDown\" /> <!-- typo -->\n// after\n<behaviors:OnEventBehavior EventName=\"MouseLeftButtonDown\" />","handlingStrategy":"validation","validationCode":"if (target.GetType().GetEvent(eventName) == null)\n    throw new InvalidOperationException($\"'{eventName}' is not an event on {target.GetType()}\");","typeGuard":"static bool HasEvent(object target, string eventName) =>\n    !string.IsNullOrEmpty(eventName) && target?.GetType().GetEvent(eventName) != null;","tryCatchPattern":"try\n{\n    element.Behaviors.Add(behavior);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Impossible to find a valid event\"))\n{\n    logger.Error(ex, $\"Event '{behavior.EventName}' does not exist on {element.GetType()}\");\n}","preventionTips":["Verify the event name exists on the attached control with reflection or docs.","Watch for typos in EventName attributes in XAML.","Re-check EventName values after upgrading control libraries where event APIs changed."],"tags":["wpf","reflection","behavior","event-not-found"],"backgroundTag":"resource-not-found","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"}