Closed ducanhtk5 closed 1 year ago
@jbogard Please check this urgent bug. My project information: .NET 7.0.3 (latest today). Type: Aspnetcore MVC
Thank you!
I also got this issue
@normandev92 @ducanhtk5 Please try.
builder.Services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssemblies(typeof(Startup).Assembly, typeof(YourHandler).Assembly);
});
@normandev92 @ducanhtk5 Please try.
builder.Services.AddMediatR(cfg => { cfg.RegisterServicesFromAssemblies(typeof(Startup).Assembly, typeof(YourHandler).Assembly); });
Hey, this works for me but what if I dont have a Startup?
Can confirm. Since upgrading my application crashes.
Same issue here
Same issue, was working before
@normandev92 @ducanhtk5 Please try.
builder.Services.AddMediatR(cfg => { cfg.RegisterServicesFromAssemblies(typeof(Startup).Assembly, typeof(YourHandler).Assembly); });
That sort of worked for me however due to change breaking changes in v12 I've ported any handlers which implemented
~~AsyncRequestHandler
to implement IRequestHandler
. Those handlers are still breaking with the following error:
An example command would be:
REMOVED
With a corresponding handler:
REMOVED
Previously the handler would have been defined as:
REMOVED
I've probably missed something in the upgrade process or I'm doing something unrecommended. I'm looking to see if I can fix it.
I should point out that I'm using the MediatR.Extensions.Microsoft.DependencyInjection package to manage DI.
So it turns out I'm an idiot and had implemented IRequest<T>
instead of IRequestHandler<T>
in one of my handlers.
Using the suggestion above resolves the initial issue.
@normandev92 @ducanhtk5 Please try.
builder.Services.AddMediatR(cfg => { cfg.RegisterServicesFromAssemblies(typeof(Startup).Assembly, typeof(YourHandler).Assembly); });
Good now. Thank you!
@normandev92 @ducanhtk5 Please try.
builder.Services.AddMediatR(cfg => { cfg.RegisterServicesFromAssemblies(typeof(Startup).Assembly, typeof(YourHandler).Assembly); });
Hey, this works for me but what if I dont have a Startup?
Here you're just referencing a type that contains MediatR's services (handlers, etc.). It doesn't need to be the Startup class.
I've had the same problem today after upgrading to version 12.0
this worked for me too:
builder.Services.AddMediatR(cfg => { cfg.RegisterServicesFromAssemblies(typeof(BaseHandler).Assembly); });
See the release notes:
https://github.com/jbogard/MediatR/releases/tag/v12.0.0
And upgrade guide:
https://github.com/jbogard/MediatR/wiki/Migration-Guide-11.x-to-12.0
In case someone finds this helpful what I did is use
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.Load("NameOfLibraryThatHasHandlers")));
for dotnet 7 and it worked.
I received an error: System.TypeLoadException: Could not load type 'MediatR.ServiceFactory' from assembly 'MediatR, Version=12.0.0.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'.