I'm trying to generate a database from the terminal of VS code using SQL Operations Studio, whenever I try to generate a migration this error occurs.
dotnet ef migrations add init
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly '/usr/local/share/dotnet/sdk/2.1.401/DotnetTools/dotnet-ef/2.1.2/tools/netcoreapp2.1/any/tools/netcoreapp2.0/any/ef.dll'. The located assembly's manifestdefinition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
This is how my
.csproj looks like now
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.2" /> </ItemGroup> </Project>
Any workaround for this?
This can also happen if you have
Microsoft.EntityFrameworkCore.Design package added to the wrong project.
I added the package to
project A (netcore). Later I decided to make project A to target
netstandard. I then created
Project B (netcore) which reference
project A (now netstandard).
When I try to create migration in project B the build succeeds but migration would fail because
Microsoft.EntityFrameworkCore.Design was referenced in A instead of B. Moving the nuget reference to B fixes the problem.