LuckyPennySoftware/MediatR · error · InvalidOperationException
Could not find method {nameof(IRequestExceptionHandler<TRequ
Error message
Could not find method {nameof(IRequestExceptionHandler<TRequest, TResponse, Exception>.Handle)} on type {exceptionHandlerInterfaceType} What it means
Thrown by GetMethodInfoForHandler if reflection cannot locate the Handle method on the synthesized IRequestExceptionHandler<TRequest,TResponse,TException> interface built via MakeGenericType. This is a defensive invariant: Handle is declared on the interface and should always resolve; firing it points to an abnormal runtime/build/proxying condition, not normal usage.
Source
Thrown at src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs:102
}
private IEnumerable<(Type ExceptionType, object Handler)> GetHandlersForException(Type exceptionType, TRequest request)
{
var exceptionHandlerInterfaceType = typeof(IRequestExceptionHandler<,,>).MakeGenericType(typeof(TRequest), typeof(TResponse), exceptionType);
var enumerableExceptionHandlerInterfaceType = typeof(IEnumerable<>).MakeGenericType(exceptionHandlerInterfaceType);
var exceptionHandlers = (IEnumerable<object>) _serviceProvider.GetRequiredService(enumerableExceptionHandlerInterfaceType);
return HandlersOrderer.Prioritize(exceptionHandlers.ToList(), request)
.Select(handler => (exceptionType, action: handler));
}
private static MethodInfo GetMethodInfoForHandler(Type exceptionType)
{
var exceptionHandlerInterfaceType = typeof(IRequestExceptionHandler<,,>).MakeGenericType(typeof(TRequest), typeof(TResponse), exceptionType);
var handleMethodInfo = exceptionHandlerInterfaceType.GetMethod(nameof(IRequestExceptionHandler<TRequest, TResponse, Exception>.Handle))
?? throw new InvalidOperationException($"Could not find method {nameof(IRequestExceptionHandler<TRequest, TResponse, Exception>.Handle)} on type {exceptionHandlerInterfaceType}");
return handleMethodInfo;
}
}View on GitHub (pinned to 916ef1b3d6)
Solutions
- Align MediatR package versions across all projects/assemblies in the solution.
- Ensure any proxy/weaver retains the Handle method on the IRequestExceptionHandler<,,> interface.
- Clean and rebuild to discard stale compiled artifacts.
- Reproduce in a minimal console app to rule out environment-specific reflection limits.
Defensive patterns
Strategy: validation
Validate before calling
var method = typeof(IRequestExceptionHandler<MyReq, MyResp, MyException>).GetMethod("Handle");
Debug.Assert(method is not null, "Handle must exist on IRequestExceptionHandler<,,>"); Prevention
- Keep a single MediatR version in the dependency graph.
- Do not strip interface methods when proxying exception handlers.
When it happens
Trigger: Should not occur under standard .NET. Possible with dynamic proxies that drop the interface method, IL weavers that alter the interface, partial-trust reflection restrictions, or a corrupt/version-mismatched MediatR assembly.
Common situations: Proxy frameworks (Castle, Moq) mocking exception handlers without preserving Handle; AOP weavers; mismatched MediatR versions in the dependency graph.
Related errors
- Could not find method {nameof(IRequestExceptionAction<TReque
- Did not return a Task from the exception handler.
- Could not create task for action method {actionForException.
- 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/cd8561d74470a6f5.
Report an issue: GitHub.