{"record":{"id":"5a509790e6f0ca3d","repo":"PrismLibrary/Prism","slug":"no-matching-event-eventname-on-attached-type-bindable","errorCode":null,"errorMessage":"No matching event '{EventName}' on attached type '{bindable.GetType().Name}'","messagePattern":"No matching event '(.+?)' on attached type '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Behaviors/EventToCommandBehavior.cs","lineNumber":161,"sourceCode":"        set => SetValue(EventArgsConverterParameterProperty, value);\n    }\n\n    /// <summary>\n    /// Subscribes to the event <see cref=\"BindableObject\"/> object\n    /// </summary>\n    /// <param name=\"bindable\">Bindable object that is source of event to Attach</param>\n    /// <exception cref=\"ArgumentException\">Thrown if no matching event exists on \n    /// <see cref=\"BindableObject\"/></exception>\n    protected override void OnAttachedTo(BindableObject bindable)\n    {\n        base.OnAttachedTo(bindable);\n\n        _eventInfo = AssociatedObject\n            .GetType()\n            .GetRuntimeEvent(EventName);\n        if (_eventInfo == null)\n        {\n            throw new ArgumentException(\n                $\"No matching event '{EventName}' on attached type '{bindable.GetType().Name}'\");\n        }\n\n        AddEventHandler(_eventInfo, AssociatedObject, OnEventRaised);\n    }\n\n    /// <summary>\n    /// Unsubscribes from the event on <paramref name=\"bindable\"/>\n    /// </summary>\n    /// <param name=\"bindable\"><see cref=\"BindableObject\"/> that is source of event</param>\n    protected override void OnDetachingFrom(BindableObject bindable)\n    {\n        if (_handler != null)\n        {\n            _eventInfo.RemoveEventHandler(AssociatedObject, _handler);\n        }\n        _handler = null;\n        _eventInfo = null;","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Behaviors/EventToCommandBehavior.cs#L143-L179","documentation":"Prism.Maui's EventToCommandBehavior resolves the event named by its EventName property on the attached control via GetRuntimeEvent; if reflection finds no such event, it throws ArgumentException. The behavior can only wire events that actually exist on the AssociatedObject type.","triggerScenarios":"Setting EventName to a name that doesn't exist on the attached control's type (typo, casing mismatch, event present only on a different platform/control), or attaching the behavior to a bindable whose runtime type differs from the one the event name was written for.","commonSituations":"Copying a behavior XAML snippet between controls (e.g. ItemTapped exists on ListView but not CollectionView); renaming events after a MAUI API change; attaching the behavior in a shared style applied to many control types.","solutions":["Correct the EventName to an event that exists on the attached control (check the exact casing).","Verify the target control type actually declares the event (CollectionView vs ListView differences).","Attach the behavior only via a targeted style/DataTemplate for the correct control type.","If the event is platform-specific, guard with platform checks or use a different behavior."],"exampleFix":"<!-- before -->\n<prism:EventToCommandBehavior EventName=\"ItemSelected\" Command=\"{Binding SelectedCommand}\" />\n<!-- after (CollectionView) -->\n<prism:EventToCommandBehavior EventName=\"SelectionChanged\" Command=\"{Binding SelectedCommand}\" />","handlingStrategy":"validation","validationCode":"var hasEvent = AssociatedObject?.GetType().GetRuntimeEvent(EventName) is not null;\nif (!hasEvent) throw new ArgumentException($\"Event '{EventName}' not found on control before attaching behavior\");","typeGuard":"bool EventExists(object control, string name) => control.GetType().GetRuntimeEvent(name) is not null;","tryCatchPattern":"try { /* attach EventToCommandBehavior */ }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"No matching event\")) { /* fix EventName */ }","preventionTips":["Verify EventName against the exact control type (CollectionView vs ListView differ)","Avoid sharing one behavior style across different control types","Compile-time check: reference the event via a lambda-based wiring where possible"],"tags":["maui","reflection","events","behavior"],"backgroundTag":"resource-not-found","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}