LuckyPennySoftware/MediatR · error · InvalidOperationException

Could not find method {nameof(IRequestExceptionAction<TReque

Error message

Could not find method {nameof(IRequestExceptionAction<TRequest, Exception>.Execute)} on type {exceptionActionInterfaceType}

What it means

Thrown by GetMethodInfoForAction if reflection cannot find the Execute method on the synthesized IRequestExceptionAction<TRequest, TException> interface built via MakeGenericType. This is a defensive guard: under normal .NET behavior Execute always exists on that interface, so this firing indicates a corrupted build, a non-conforming runtime, or an exotic reflection/proxying environment.

Source

Thrown at src/MediatR/Pipeline/RequestExceptionActionProcessorBehavior.cs:87

    private IEnumerable<(Type ExceptionType, object Action)> GetActionsForException(Type exceptionType, TRequest request)
    {
        var exceptionActionInterfaceType = typeof(IRequestExceptionAction<,>).MakeGenericType(typeof(TRequest), exceptionType);
        var enumerableExceptionActionInterfaceType = typeof(IEnumerable<>).MakeGenericType(exceptionActionInterfaceType);

        var actionsForException = (IEnumerable<object>)_serviceProvider.GetRequiredService(enumerableExceptionActionInterfaceType);

        return HandlersOrderer.Prioritize(actionsForException.ToList(), request)
            .Select(action => (exceptionType, action));
    }

    private static MethodInfo GetMethodInfoForAction(Type exceptionType)
    {
        var exceptionActionInterfaceType = typeof(IRequestExceptionAction<,>).MakeGenericType(typeof(TRequest), exceptionType);

        var actionMethodInfo =
            exceptionActionInterfaceType.GetMethod(nameof(IRequestExceptionAction<TRequest, Exception>.Execute))
            ?? throw new InvalidOperationException(
                $"Could not find method {nameof(IRequestExceptionAction<TRequest, Exception>.Execute)} on type {exceptionActionInterfaceType}");

        return actionMethodInfo;
    }
}

View on GitHub (pinned to 916ef1b3d6)

Solutions

  1. Verify the MediatR package version matches across all referenced assemblies (no version mismatch).
  2. If proxying/weaving exception actions, ensure the proxy retains the Execute method on the IRequestExceptionAction<,> interface.
  3. Run a clean rebuild to rule out stale/compiled artifacts.
  4. As a last resort, isolate the exception action in a minimal project to confirm the runtime can resolve the method.
Defensive patterns

Strategy: validation

Validate before calling

// Sanity check the interface shape before relying on it
var method = typeof(IRequestExceptionAction<MyRequest, MyException>).GetMethod("Execute");
Debug.Assert(method is not null, "Execute must exist on IRequestExceptionAction<,>");

Prevention

When it happens

Trigger: Effectively never under standard .NET: the interface is constructed from IRequestExceptionAction<,> which declares Execute. Could surface with dynamic proxies / IL weaving that strip interface methods, partial-trust reflection limits, or a hand-edited/incompatible MediatR binary.

Common situations: Dynamic proxy frameworks (Castle DynamicProxy, Moq) generating type mocks without the method; AOP weavers altering the interface; mismatched MediatR assembly versions where the interface shape changed.

Related errors


AI-assisted analysis of LuckyPennySoftware/MediatR@916ef1b3d6 (2026-08-13). Data as JSON: /api/errors/7752dbf449c3ff49. Report an issue: GitHub.