dotnet/aspnetcore · error · InvalidOperationException

The event handler parameter type {declaredType.FullName} for

Error message

The event handler parameter type {declaredType.FullName} for event must inherit from {typeof(EventArgs).FullName}.

What it means

Blazor event handlers that accept a single parameter require that parameter to be assignable to System.EventArgs (or one of its subclasses like MouseEventArgs, KeyboardEventArgs, ChangeEventArgs). When EventArgsTypeCache.GetEventArgsType encounters a single-parameter method whose parameter type does not inherit from EventArgs, it throws InvalidOperationException. This ensures type safety for DOM event dispatch.

Source

Thrown at src/Components/Components/src/RenderTree/EventArgsTypeCache.cs:44

            var parameterInfos = methodInfo.GetParameters();
            if (parameterInfos.Length == 0)
            {
                return typeof(EventArgs);
            }
            else if (parameterInfos.Length > 1)
            {
                throw new InvalidOperationException($"The method {methodInfo} cannot be used as an event handler because it declares more than one parameter.");
            }
            else
            {
                var declaredType = parameterInfos[0].ParameterType;
                if (typeof(EventArgs).IsAssignableFrom(declaredType))
                {
                    return declaredType;
                }
                else
                {
                    throw new InvalidOperationException($"The event handler parameter type {declaredType.FullName} for event must inherit from {typeof(EventArgs).FullName}.");
                }
            }
        });
    }
}

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Use the correct EventArgs subclass for the event type: MouseEventArgs for @onclick/@onmouseover, KeyboardEventArgs for @onkeydown/@onkeyup, ChangeEventArgs for @onchange/@oninput.
  2. If you need to pass custom data, use a lambda closure instead: @onclick="@(() => Handler(myData))".
  3. If no event argument is needed, declare the handler with zero parameters.
  4. Check the Blazor docs for the correct EventArgs subclass mapping for each DOM event.

Example fix

<!-- before -->
@onclick="HandleClick"
@code {
    void HandleClick(int id) { } // int is not EventArgs
}

<!-- after -->
@onclick="@(e => HandleClick(itemId))"
@code {
    void HandleClick(int id) { }
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate that a handler's single parameter inherits from EventArgs
static bool HasValidEventArgsParameter(MethodInfo method)
{
    var parms = method.GetParameters();
    if (parms.Length != 1) return parms.Length == 0;
    return typeof(EventArgs).IsAssignableFrom(parms[0].ParameterType);
}

Type guard

// In Razor, use the correct EventArgs subclass implicitly:
// @onclick="Handler" where void Handler(MouseEventArgs e) { }

Prevention

When it happens

Trigger: Using a method as a Blazor event handler (@onclick="MyMethod") where MyMethod accepts a single parameter whose type is not an EventArgs subclass, e.g., void MyMethod(int id) or void MyMethod(MyCustomDto data). The framework resolves the type via reflection and rejects non-EventArgs types.

Common situations: Confusion about Blazor event handler signatures; trying to pass custom data objects as the event argument; migrating from a different framework where arbitrary types were allowed; using a method that takes a primitive type (int, string) as the event handler.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/1fae009e01f1e27c. Report an issue: GitHub.