Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not load type Mediatr.IRequest #692

Closed
bend opened this issue Jan 11, 2022 · 16 comments
Closed

Could not load type Mediatr.IRequest #692

bend opened this issue Jan 11, 2022 · 16 comments

Comments

@bend
Copy link

bend commented Jan 11, 2022

Hi,
Since update to Mediatr 10, I have the following error at runtime:
Could not load type 'MediatR.IRequest 1' from assembly 'MediatR, Version=10.0.0.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'

Any idea what's going on ?

@vRITHNER
Copy link

vRITHNER commented Jan 12, 2022

Same issue for me with an AspNet.Core 6.0 app

"Could not load type 'MediatR.IRequest`1' from assembly 'MediatR, Version=10.0.0.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'."

@jbogard
Copy link
Owner

jbogard commented Jan 12, 2022

I've got it running on .NET 6, is there a repro? Are you using the DI package?

@jbogard
Copy link
Owner

jbogard commented Jan 12, 2022

And the exception message is correct - those types are in a separate MediatR.Contracts assembly as mentioned in the release notes. But user code shouldn't care about that in scenarios I looked at.

@vRITHNER
Copy link

txs for coming back. Sadly, I can't send you the project cause it's a customer code.
I'll try to reproduce it in a total separate poc project and I'll come back to you..
Txs

@bend
Copy link
Author

bend commented Jan 12, 2022

@jbogard I'm using .Net5. I'm not using the DI package (I only have Mediatr package installed)
Thx

@jbogard
Copy link
Owner

jbogard commented Jan 12, 2022

If you check your stack trace, do you have code looking for the IRequest type from the MediatR assembly?

@bend
Copy link
Author

bend commented Jan 13, 2022

@jbogard I don't see that in the stacktrade. However, I have the issue in multiple projects.
[CS7069] Reference to type 'INotification' claims it is defined in 'MediatR', but it could not be found

I tried to force the update by install Mediatr10 in the project itself but I have the same issue.
Thanks

@jbogard
Copy link
Owner

jbogard commented Jan 13, 2022

I don't know how to fix this without a minimal repro. I can only share that those request types are in a separate package/assembly - MediatR.Contracts, which is referenced by the MediatR package starting with version 10.

@killergege
Copy link

killergege commented Jan 13, 2022

Note that I have the same issue, but it happens when calling MediatR.Extensions.FluentValidation.AspNetCore.AddFluentValidation().
But I realize that this is an external lib.

Nobody mentions here what triggers the exception, so maybe we all have the same issue (with different external libs) ?

In my case, the exception happen on the second line.

        services.AddMediatR(typeof(MyRequestHandler).GetTypeInfo().Assembly);
        services.AddFluentValidation(new[] { typeof(MyRequestHandlerValidator).GetTypeInfo().Assembly });

Removing it fixes the issue.

I have a very stripped down version of my project with the issue, but if the issue is in another lib, not sure this would be useful.

Edit : my issue was fixed by the update of the external lib.

@DMPatod
Copy link

DMPatod commented Jan 21, 2022

I'm using dotnet 6 a had to drop to MediatR 8.1 and MediatR.Extensions.Microsoft.DependencyInjection 8.1 to solve this.
Neither 10.0.0 and 9.0.0 worked for me.

@dhilgarth
Copy link

dhilgarth commented Jan 31, 2022

@jbogard Also coming across this CS7069. My scenario:
a Nuget package, on .NET 5 and MediatR 9.0.0 is referenced by a class library on .NET 6 and MediatR 10.0.1.
The Nuget package contains a command that implements IRequest. Trying to mediator.Send(new CommandFromPackage()) will result in this error on the Send method.

I think that's your repro there. At least it sounds reasonable.

@aboudoux
Copy link

aboudoux commented Feb 8, 2022

Hi,
Same problem here.
everything was fine until I include Blazor-State in my project.

Downgrading the solution to MediatR 9 resolve the issue for me.

@jbogard
Copy link
Owner

jbogard commented Feb 8, 2022

The assemblies were split out and IRequest is in a separate assembly. If things are referencing both older and newer versions, things are going to break. Anything referencing MediatR will need to update major versions.

This is pretty normal for major versions, you can't mix major versions of assemblies without expecting some failures.

@ydie22
Copy link
Contributor

ydie22 commented Nov 14, 2022

Hi,

I just opened a pull request that should solve the issue described here. See #800.

I understand that major upgrades contain breaking changes, however this one is particularly hard to solve for us. We have tens of contracts packages that are currently referring to MediatR 8.1 (where the interfaces for request types were living until then), and those are consumed by many services. We cannot afford upgrading everything at once. I think the proposed change will allow upgrading a service to the latest MediatR version while still referencing contract packages that consume MediatR 8.1 (provided of course there are no other breaking changes than this one that affect the code base).

Thx

@jbogard jbogard reopened this Nov 19, 2022
@jbogard
Copy link
Owner

jbogard commented Nov 19, 2022

Fixed by #800

@jbogard jbogard closed this as completed Nov 19, 2022
@chrisira
Copy link

I solved the problem by downgrading from mediatr 11.10 t0 11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants