HandyOrg/HandyControl · error · ArgumentException

ExceptionStringTable.EventTriggerCannotFindEventNameExceptio…

Error message

ExceptionStringTable.EventTriggerCannotFindEventNameExceptionMessage

What it means

When an EventTriggerBase registers its handler, it looks up EventName via reflection on the source object's type. If the event does not exist and a SourceObject is set, ArgumentException EventTriggerCannotFindEventNameExceptionMessage is thrown with the event name and the type searched.

Solutions

  1. Correct EventName to an event that exists on the source object's type (e.g. 'Click', 'MouseLeftButtonDown').
  2. Verify the resolved SourceObject is the intended type that actually declares the event.
  3. Check spelling/casing of EventName; it is case-sensitive via Type.GetEvent.
  4. If the event was removed by a library upgrade, update to the new event name or add a compat shim.

Example fix

<!-- before -->
<i:EventTrigger EventName="Clicck" SourceName="okButton" />
<!-- after -->
<i:EventTrigger EventName="Click" SourceName="okButton" />
Defensive patterns

Strategy: validation

Validate before calling

if (sourceObject?.GetType().GetEvent(eventName) == null)
    Console.WriteLine($"Event '{eventName}' does not exist on {sourceObject.GetType().Name}");

Type guard

static bool EventExists(object source, string eventName) =>
    source != null && source.GetType().GetEvent(eventName) != null;

Try / catch

try { trigger.Attach(associatedObject); }
catch (ArgumentException ex) when (ex.Message.Contains("CannotFindEventName")) {
    // correct EventName for this source type
}

Prevention

When it happens

Trigger: Setting EventTrigger.EventName (via OnEventNameChanged) or changing the source (OnSourceChangedImpl) so RegisterEvent is called on an object whose type has no event with that name.

Common situations: Typo in EventName in XAML; renaming or removing an event in a control library update; pointing the trigger at a base/plain type (e.g. FrameworkElement) that lacks the event; case-sensitive mismatch in event name.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/0fb560ab4a72bca5. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/System.Windows.Interactivity/EventTriggerBase.cs:232

        if (args.NewValue == null)
        {
            base2.OnSourceChanged(args.OldValue, newSource);
        }
        else
        {
            if (args.OldValue == null && newSource != null)
                base2.UnregisterEvent(newSource, base2.GetEventName());
            base2.OnSourceChanged(args.OldValue, args.NewValue);
        }
    }

    private void RegisterEvent(object obj, string eventName)
    {
        var eventInfo = obj.GetType().GetEvent(eventName);
        if (eventInfo == null)
        {
            if (SourceObject != null)
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                    ExceptionStringTable.EventTriggerCannotFindEventNameExceptionMessage,
                    new object[] { eventName, obj.GetType().Name }));
        }
        else if (!IsValidEvent(eventInfo))
        {
            if (SourceObject != null)
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                    ExceptionStringTable.EventTriggerBaseInvalidEventExceptionMessage,
                    new object[] { eventName, obj.GetType().Name }));
        }
        else
        {
            _eventHandlerMethodInfo =
                typeof(EventTriggerBase).GetMethod("OnEventImpl", BindingFlags.NonPublic | BindingFlags.Instance);
            eventInfo.AddEventHandler(obj,
                Delegate.CreateDelegate(eventInfo.EventHandlerType, this, _eventHandlerMethodInfo ?? throw new InvalidOperationException()));
        }
    }

View on GitHub (pinned to 2c0875ebd6)