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
- Verify the MediatR package version matches across all referenced assemblies (no version mismatch).
- If proxying/weaving exception actions, ensure the proxy retains the Execute method on the IRequestExceptionAction<,> interface.
- Run a clean rebuild to rule out stale/compiled artifacts.
- 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
- Pin MediatR to a single version across the solution to avoid interface-shape drift.
- Avoid proxying/weaving IRequestExceptionAction types unless you preserve Execute.
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
- Could not create task for action method {actionForException.
- Could not find method {nameof(IRequestExceptionHandler<TRequ
- Did not return a Task from the exception handler.
- Open behavior type can not be null.
- The type "{openBehaviorType.Name}" must implement IPipelineB
AI-assisted analysis of LuckyPennySoftware/MediatR@916ef1b3d6 (2026-08-13).
Data as JSON: /api/errors/7752dbf449c3ff49.
Report an issue: GitHub.