-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 file or assembly Microsoft.EntityFrameworkCore #9251
Comments
Make sure that all the packages of AspNet core you are referring are from 1.1.2 release. Mixing versions from different releases are not supported and may not work always. If you are unsure then share your csproj file. If above doesn't help then you may need to generate binding redirects. See dotnet/msbuild#1310 for the issue and work-around. |
Here's my csproj file:
All the dependencies are at their latest versions for .NET Core 1.1. I'm looking into binding redirects now but I'm not sure what they are and how they can help address my issue. Can you provide a bit more information regarding it? |
https://www.nuget.org/packages/Npgsql.EntityFrameworkCore.PostgreSQL/1.1.0 Package
This is documentation for Binding redirect. https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element Essentially, when you have multiple versions of same assembly referenced in your project, you need to generate a binding redirect so that calls to all different versions of assembly can be redirected to single version which is actually made available to project. In the absence of that, you program will try to load different version of assembly than what is available and throw above exception. In above case, you are referencing different versions of EFCore package. Different versions of same package have different assembly versions in them. |
@smitpatel, I was under the impression it's totally fine to have a lower version of a provider referencing a high version of the core, since patch versions supposed to maintain 100% backwards compatibility. Nuget is supposed to automatically generate binding redirects to the latest version of EF Core (maybe some issue with that is at the source of the problem here?). Unless I'm missing something, the csproj above in itself isn't supposed to create any issues... |
@roji - You are right in the terms of compatibility though binding redirects are not generated always for class library. See dotnet/msbuild#1310 |
OK, wasn't aware of the library binding redirect issue... In any case it seems odd to ask provider writers to release patch versions for every EF Core patch version, even if there's nothing new on their end, solely to update the dependency etc. In any case FYI I plan to release Npgsql.EntityFrameworkCore.PostgreSQL 1.1.1 later today, which will depend on the latest EF Core, so in this particular instance the problem should go away. |
I suppose patches for EF are not critical (non-security kind so far). So it would be fine not to move to patch version unless you need a fix which is in patch.
That is interesting question because we release new versions even without fix because dependency changed. I am not certain if that was done because its just single release cycle or we want to update. Perhaps @divega or @ajcvickers can provide guidance on what provider writers should do. |
Yeah, it seems that up to now there's been a general single release cycle (.NET Core/EF Core/Microsoft.Extensions), which is probably at least part of the story. I just released Npgsql's provider version 1.1.1, which takes a dependency on EF Core 1.1.2 (simply because I didn't release sooner), I could have skipped 1.1.1 and released 1.1.2 to maintain version parity with you guys. However, imagine what happens if I have a critical fix I need to get out - unless I go with 1.1.1.1 we lose version sync (since I'm forced to publish 1.1.2 while EF Core is still at 1.1.1). As a general statement, I'm not sure I see the enormous value in having version sync across the board. Now that .NET Core/Standard 2.0 is out and presumably things stabilize a little, it would make sense for me for the EF Core team to start having its own release schedule based on its own features/progress rather than get tied down by what's happening in .NET Core etc. Anyway, just some thoughts, nothing very critical... |
@smitpatel I uninstalled all the dependencies and installed only the high-level ones (as you mentioned, they bring the required ones along with them). This is my csproj file now:
But I'm still getting the same error, but I have noticed something.
Focus on this line:
Why is my class library project looking for the version 1.1.2? I uninstalled everything and installed the main dependencies only, which in turn installed EF Core and others. Not sure why the application is looking for v1.1.2 though, when clearly everything is at v1.1. |
@humzakhan as I wrote above, the newly-released Npgsql.EntityFrameworkCore.PostgreSQL 1.1.1 depends on Microsoft.EntityFrameworkCore 1.1.2, the versions aren't in sync; you can see this in the dependencies section of the nuget page. This isn't a problem - Npgsql is supposed to bring in the proper version of EF Core and that's that. The question is why your build isn't finding EF Core 1.1.2. I'm assuming you've properly restored after making the change, try to understand what's being brought in and what assemblies are alongside your binary if the error occurs while running (as opposed to building). |
Fixed it. The class library project which had all these EF packages installed (or my data access layer) was being referenced as an assembly in the main project. Instead of that, I referenced it as a project and everything worked fine. Probably this is some sort of issue with referencing class libraries present on disk, I read about it somewhere. Will open an issue regarding this on the .NET Core repository because that is where it belongs (if I'm not mistaken). |
Issue
I have a class library project targeting .NET Core 1.1 with Entity Framework Core v1.1.2 installed. It contains all the domain logic. Whenever I call methods from my EF Core project in other projects, I'm having this exception:
All my projects are targeting .NET Core 1.1 and I'm not sure what is causing this behavior. Any ideas? All the dependencies are installed correctly, database migrations work perfectly fine but I'm not able to use any of my methods involving database calls. It fails with the exception as mentioned above.
The text was updated successfully, but these errors were encountered: