In a ASP.NET Core project I run Add Controller
- API Controller with actions, using Entity Framework
from Visual Studio 2019.
I then get the following error:
Error
There was an error running the selected code generator: 'Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=5.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'
If I take a look at Git I can see that Visual Studio has automatically downgraded Microsoft.EntityFrameworkCore.SqlServer
and Microsoft.EntityFrameworkCore.Tools
to 5.0.9
.
If I run the exact same code again it will work.
I'm running the latest Microsoft Visual Studio Community 2019 Version 16.11.3
and all the latest NuGet packages. I can only update Microsoft.EntityFrameworkCore.SqlServer
and Microsoft.EntityFrameworkCore.Tools
that Visual Studio automatically downgraded.
Is this a bug in Visual Studio or something else?
CodePudding user response:
This could be possible if you have two dependencies (project, package) and each of them depends on EF but from different versions. Also, dependence can be transitive.
For the old .csproj
this could be fixed by the child XML element. I am not sure if there is an alternative for the new .csproj
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
Also, this issue is fixed in the alternative for NuGet https://fsprojects.github.io/Paket/
CodePudding user response:
try these
- update all of your NuGet package
- clean solution
- rebuild