{
"error": [
"Error constructing handler for request of type MediatR.IRequestHandler`2[NPPDPayment.Application.Payment.Command.DuplicatePaymentCheckCommand,NPPDPayment.Application.Common.ApiResponse`1[NPPDPayment.Application.Common.DuplicatePaymentResponse]]. Register your handlers with the container. See the samples in GitHub for examples."
],
"stackTrace": " at MediatR.Internal.RequestHandlerBase.GetHandler[THandler](ServiceFactory factory)\r\n at MediatR.Internal.RequestHandlerWrapperImpl`2.<>c__DisplayClass1_0.<Handle>g__Handler|0()\r\n at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n at NPPDPayment.Application.Infrastructure.RequestPerformanceBehaviour`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n at NPPDPayment.WebAPI.Controllers.PaymentController.DuplicatePayment(DuplicatePaymentCheckCommand command)\r\n at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at System.Threading.Tasks.ValueTask`1.get_Result()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()"
}
Hello, I solved using this alternative
services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies());Sweet stack trace
This worked for me. Thanks.
Just sharing in case this helps someone:
I had the same issue and in my case it was caused by a service passed via DependencyInejction in my handler constructor; the dependency was not correctly registered in the ApplicationInstaller, i.e. I was missing this line:
services.AddScoped<MyService>();@mehzan07 See my previous comment. It 100% is not MediatR, but can be a bit tricky to debug.
Look at or log the “InnerException” of the thrown Exception and it will show the underlying exception which caused this
@jbogard see: https://github.com/jbogard/MediatR/blob/master/src/MediatR/Wrappers/HandlerBase.cs#L15
how about just removing the catch entirely or use ExceptionDispatchInfo.Capture().Throw to the point the underlying exception is just bubbled up to the user. I’ve seen a lot of issues opened here like this and it’s never MediatR. Just letting the underlying exception be thrown would make that more obvious. the handler == null case can stay as is.
Unfortunately, the exception message points us to look at handlers, when the issue isn’t with the handlers themselves.
Had the same issue In my code I had
services.AddOptions();beforeservices.AddMediatR(typeof(myAssemblyStuff).GetTypeInfo().Assembly);Changed it and it worked again
Hello, i had the same problem, with a Azure Functions Project, and it was due to the lack of the connection string in the file local.settings.json.
I found out thanks to the msg posted by @Zodt in https://github.com/jbogard/MediatR/issues/497#issuecomment-889855864_
To solved it, I included the “ConnectionStrings” tag into local.settings.json, after “Values” tag. Like bellow:
I found the solution of that problem
I was getting the same This can resolve your issue, it works for me builder.Services.AddMediatR(typeof(MyQuery).GetTypeInfo().Assembly);
I had the same problem but the error was an enviroment configuration, I did not have the connection to the database,
I realize this is closed, but in case someone else comes here with my case, then make sure you don’t forgot to register something. Like my repository that I was attempting to have implemented via a controller.
Is my case was an issue with the connection string in one of the repositories the handler depends on. Better logging in the app helps.
I think the reason for this error is somewhere else. in my case wrong migration code.