{"record":{"id":"f4662cbb98e4ecbf","repo":"elsa-workflows/elsa-core","slug":"there-is-no-handler-to-handle-the-requesttype-fullname","errorCode":null,"errorMessage":"There is no handler to handle the {requestType.FullName} request","messagePattern":"There is no handler to handle the (.+?) request","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/common/Elsa.Mediator/Middleware/Request/Components/RequestHandlerInvokerMiddleware.cs","lineNumber":25,"sourceCode":"/// A middleware component that invokes request handlers.\n/// </summary>\npublic class RequestHandlerInvokerMiddleware(\n    RequestMiddlewareDelegate next,\n    IEnumerable<IRequestHandler> requestHandlers) : IRequestMiddleware\n{\n    /// <inheritdoc />\n    public async ValueTask InvokeAsync(RequestContext context)\n    {\n\n        // Find all handlers for the specified request.\n        var request = context.Request;\n        var requestType = request.GetType();\n        var responseType = context.ResponseType;\n        var handlerType = typeof(IRequestHandler<,>).MakeGenericType(requestType, responseType);\n        var handlers = requestHandlers.Where(x => handlerType.IsInstanceOfType(x)).ToArray();\n        \n        if (handlers.Length == 0)\n            throw new InvalidOperationException($\"There is no handler to handle the {requestType.FullName} request\");\n\n        if (handlers.Length > 1)\n            throw new InvalidOperationException($\"Multiple handlers were found to handle the {requestType.FullName} request\");\n\n        var handler = handlers.First();\n        var handleMethod = handlerType.GetMethod(\"HandleAsync\")!;\n        var cancellationToken = context.CancellationToken;\n        var task = (Task)handleMethod.Invoke(handler, [request, cancellationToken])!;\n        await task.ConfigureAwait(false);\n\n        // Get result of task.\n        var taskWithReturnType = typeof(Task<>).MakeGenericType(responseType);\n        var resultProperty = taskWithReturnType.GetProperty(nameof(Task<object>.Result))!;\n        context.Response = resultProperty.GetValue(task)!;\n\n        // Invoke next middleware.\n        await next(context).ConfigureAwait(false);\n    }","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/common/Elsa.Mediator/Middleware/Request/Components/RequestHandlerInvokerMiddleware.cs#L7-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Register a handler for the request type, e.g. services.AddHandler<MyRequestHandler>() (or the feature's handler registration extension) in the DI setup.","Verify the handler implements IRequestHandler<TRequest, TResponse> with exactly the same request and response types as the object passed to SendAsync.","Check that the Elsa Mediator feature/module containing the handler registration is actually installed in the host.","If the handler exists, confirm there is no type mismatch (namespace or response type) introduced by a recent refactor."],"exampleFix":"// before\nawait sender.SendAsync(new MyRequest()); // throws: no handler\n// after\nservices.AddHandler<MyRequestHandler>(); // class MyRequestHandler : IRequestHandler<MyRequest, MyResponse>\nawait sender.SendAsync(new MyRequest());","handlingStrategy":"validation","validationCode":"// ensure a handler is registered before sending\nvar handlerType = typeof(IRequestHandler<MyRequest, MyResponse>);\nif (services.GetServices(handlerType).All(h => h is null))\n    throw new InvalidOperationException(\"Register an IRequestHandler<MyRequest, MyResponse> before sending MyRequest.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await sender.SendAsync(request);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"There is no handler to handle\"))\n{\n    logger.LogError(ex, \"No handler registered for {RequestType}\", request.GetType().Name);\n}","preventionTips":["Pair every request record with its handler registration in the same feature/module file.","Add a unit test that resolves IRequestHandler<TRequest,TResponse> for each request type in the module.","After refactoring response types, grep for IRequestHandler registrations referencing the old types."],"tags":["mediator","dependency-injection","missing-handler"],"backgroundTag":"missing-dependency","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}