elsa-workflows/elsa-core · error · InvalidOperationException

There is no handler to handle the

Error message

There is no handler to handle the {requestType.FullName} request

What it means

Elsa.Mediator's request middleware resolves IRequestHandler<TRequest,TResponse> implementations from the registered handler list and throws when zero handlers match the request/response type pair. This means the mediator pipeline received a request whose corresponding handler was never registered in DI, or was registered for a different request/response combination. The request can never be processed, so the library fails fast with an InvalidOperationException.

Solutions

  1. Register a handler for the request type, e.g. services.AddHandler<MyRequestHandler>() (or the feature's handler registration extension) in the DI setup.
  2. Verify the handler implements IRequestHandler<TRequest, TResponse> with exactly the same request and response types as the object passed to SendAsync.
  3. Check that the Elsa Mediator feature/module containing the handler registration is actually installed in the host.
  4. If the handler exists, confirm there is no type mismatch (namespace or response type) introduced by a recent refactor.

Example fix

// before
await sender.SendAsync(new MyRequest()); // throws: no handler
// after
services.AddHandler<MyRequestHandler>(); // class MyRequestHandler : IRequestHandler<MyRequest, MyResponse>
await sender.SendAsync(new MyRequest());
Defensive patterns

Strategy: validation

Validate before calling

// ensure a handler is registered before sending
var handlerType = typeof(IRequestHandler<MyRequest, MyResponse>);
if (services.GetServices(handlerType).All(h => h is null))
    throw new InvalidOperationException("Register an IRequestHandler<MyRequest, MyResponse> before sending MyRequest.");

Try / catch

try
{
    await sender.SendAsync(request);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("There is no handler to handle"))
{
    logger.LogError(ex, "No handler registered for {RequestType}", request.GetType().Name);
}

Prevention

When it happens

Trigger: Calling ISender.SendAsync (or mediator Send) with a request type for which no class implementing IRequestHandler<ThatRequest, ItsResponseType> is registered in the DI container; registering the handler with a mismatched response type; forgetting services.AddHandler<THandler>() / addHandler registration for the request.

Common situations: A developer adds a new request record but forgets to register its handler; a handler is registered in a different module/feature that is not loaded; refactoring changed the request's response type so the existing registration no longer matches; tests build a service provider without the Mediator feature or handler registrations.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/f4662cbb98e4ecbf. Report an issue: GitHub.

Appendix: source

Thrown at src/common/Elsa.Mediator/Middleware/Request/Components/RequestHandlerInvokerMiddleware.cs:25

/// A middleware component that invokes request handlers.
/// </summary>
public class RequestHandlerInvokerMiddleware(
    RequestMiddlewareDelegate next,
    IEnumerable<IRequestHandler> requestHandlers) : IRequestMiddleware
{
    /// <inheritdoc />
    public async ValueTask InvokeAsync(RequestContext context)
    {

        // Find all handlers for the specified request.
        var request = context.Request;
        var requestType = request.GetType();
        var responseType = context.ResponseType;
        var handlerType = typeof(IRequestHandler<,>).MakeGenericType(requestType, responseType);
        var handlers = requestHandlers.Where(x => handlerType.IsInstanceOfType(x)).ToArray();
        
        if (handlers.Length == 0)
            throw new InvalidOperationException($"There is no handler to handle the {requestType.FullName} request");

        if (handlers.Length > 1)
            throw new InvalidOperationException($"Multiple handlers were found to handle the {requestType.FullName} request");

        var handler = handlers.First();
        var handleMethod = handlerType.GetMethod("HandleAsync")!;
        var cancellationToken = context.CancellationToken;
        var task = (Task)handleMethod.Invoke(handler, [request, cancellationToken])!;
        await task.ConfigureAwait(false);

        // Get result of task.
        var taskWithReturnType = typeof(Task<>).MakeGenericType(responseType);
        var resultProperty = taskWithReturnType.GetProperty(nameof(Task<object>.Result))!;
        context.Response = resultProperty.GetValue(task)!;

        // Invoke next middleware.
        await next(context).ConfigureAwait(false);
    }

View on GitHub (pinned to fe9217bdfa)