Aspnetcore.docs: Could not load file or assembly 'Microsoft.EntityFrameworkCore

Created on 11 May 2018  Â·  12Comments  Â·  Source: dotnet/AspNetCore.Docs

When running "dotnet aspnet-codegenerator razorpage -m Movie -dc MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries" according to the instructions from this article, I met with the following error.

C:\AspNetCore\RazorPagesMovie\RazorPagesMovie>dotnet aspnet-codegenerator razorpage -m Movie -dc MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries

Welcome to .NET Core!

Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.

Telemetry

The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include command-line arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Building project ...
Finding the generator 'razorpage'...
Running the generator 'razorpage'...
Attempting to compile the application in memory.
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Movie'
Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:06.83

Anyone knows how to fix this?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Source - Docs.ms

Most helpful comment

The error is because of the different versions between packages.
Please use this command in PM.
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 2.0.3

All 12 comments

The steps suggested in this comment worked for me: https://github.com/aspnet/Docs/issues/6357#issuecomment-388380899

The error seems to be because of the different versions between packages.

Please use Install-Package command with version number like this
PM> Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 2.0.3

@StephenSZDai @jaimelr @agent3jia What version of the .NET SDK do you have installed?
dotnet --version

@Rick-Anderson
I installed 2.1.102 version

I had the same problem and can confirm it now works with v2.0.3.

The error is because of the different versions between packages.
Please use this command in PM.
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 2.0.3

@sapiencestar, I understand what you are saying, but how does one update the code / system to that it works with the latest version of Microsoft.VisualStudio.Web.CodeGeneration.Design?

At time of writing, I ran Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design with no -version, resulting in version 2.1.0.

Surely, this must be possible and I know from painful experience that the newest is not always the best, nevertheless, I'd expect in a year's time, one won't even be able to install 2.0.3.

Thanks.

I am facing a similar problem with "dotnet ef migrations list". It was working few days ago. But not working now after updating visual studio to latest(15.8.4) I guess. It is showing "Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.1.3.0".
Updating ""Microsoft.VisualStudio.Web.CodeGeneration.Design" has no effect.
Using "Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.2" which depends on EFCore package version 2.1.2 I think. Don't know how to resolve it.

See #8545

I had same problem,
dotnet version: 2.1.402
It's solved by downgrade Npgsql.EntityFrameworkCore.PostgreSQL from 2.1.2 to 2.1.0

I had same problem,
dotnet version: 2.1.6
It's solved by removing a redundant reference to EntityFrameworkCore (Microsoft.AspNetCore.All has it as a dependency)

Might need to run this:

PM>Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Utils -Version 3.0.0

https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Utils/3.0.0

Was this page helpful?
0 / 5 - 0 ratings