question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handler not found

See original GitHub issue

I’m trying to register a generic request handler for a generic request, but I’m getting the error below when calling

await _mediator.Send(new ExchangeOrderRequest<ExchangeOrderResponseSuccessEvent>());

System.InvalidOperationException: Handler was not found for request of type MediatR.IRequestHandler2[MyNamespace.ExchangeOrderRequest1[MyNamespace.ExchangeOrderResponseSuccessEvent],MediatR.Unit]. Register your handlers with the container. See the samples in GitHub for examples.

As side note, for giggles, I was able to inject an instance of IRequestHandler<ExchangeOrderRequest< ExchangeOrderResponseSuccessEvent>> into a controller just fine.

// Some assembly scanning, doesn't find my handler
services.AddMediatR(typeof(Startup), typeof(ExchangeOrderRequest), typeof(IDocumentMessage), typeof(OrderExecution.Handler));

// Try to manually add the handler.  Still doesn't find it
services.AddTransient<IRequestHandler<ExchangeOrderRequest<ExchangeOrderResponseSuccessEvent>>, ExchargeOrderRequestHandler<ExchangeOrderResponseSuccessEvent, ExchangeOrderRequest<ExchangeOrderResponseSuccessEvent>>>();




public class ExchargeOrderRequestHandler<TEvent, TRequest> : IRequestHandler<TRequest> 
	where TRequest : ExchangeOrderRequest<TEvent> 
	where TEvent : ExchangeOrderEvent
{
     // Stuff
}`

public class ExchangeOrderRequest<T>: DocumentMessage, IRequest where T: ExchangeOrderEvent
{
     // Stuff
}

public class ExchangeOrderEvent : IEvent
{
      // Stuff
 
		
}

What am I missing here?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jbogardcommented, Jul 13, 2021

Use a different container, the Microsoft DI container often can’t handle these edge cases, and this is one of them. It can’t handle partially closed generic types.

Otherwise, it might be fixed in the registration side of things, we might be able to forward registrations perhaps?

0reactions
WillMarcouillercommented, Oct 13, 2021

I use Ninject in a .Net 4.8 project and IRequestHandler<,> can’t be resolved through the ContravariantBindingResolver based on MediatR.Examples.Ninject. Could it also be the container in fault?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handler not found - python
I recently made a code in python3.x and for the interface I used a .glade file but when I run the code the...
Read more >
handler not found in main.py {lambda function }
You need to provide a dedicated handler there, import main.py and initialize Mangum. Let's prepare handler = Mangum (app,) separately. Please refer to...
Read more >
NotFound Handler for ASP.NET Core and Optimizely
The NotFound handler stores the redirects in the database. Editors can add redirects without any deployments. All redirects are edited in the Admin...
Read more >
Ansible - Handler not found on first attempt
I just found out the hard way. handlers only works with include_tasks not import_tasks . The error message is rather missdirecting. I went...
Read more >
Not Found Handler - mezzio-problem-details - Laminas Docs
This library provides a Not Found handler so that returned 404 responses are in the problem details format. This handler will create a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found