AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Could not load file or assembly 'Microsoft.EntityFrameworkCore

Open StephenSZDai opened this issue 8 years ago • 13 comments

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.

StephenSZDai avatar May 11 '18 08:05 StephenSZDai

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.

jaimelr avatar May 14 '18 00:05 jaimelr

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

agent3jia avatar May 17 '18 05:05 agent3jia

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

Rick-Anderson avatar May 17 '18 17:05 Rick-Anderson

@Rick-Anderson I installed 2.1.102 version

agent3jia avatar May 18 '18 00:05 agent3jia

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

holly-hacker avatar May 18 '18 16:05 holly-hacker

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 avatar May 23 '18 08:05 sapiencestar

@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.

ghost avatar May 30 '18 09:05 ghost

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.

gulshan avatar Sep 19 '18 13:09 gulshan

See #8545

Rick-Anderson avatar Sep 19 '18 21:09 Rick-Anderson

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

alirezapooneh avatar Nov 05 '18 19:11 alirezapooneh

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)

Paul-RHT avatar Jan 23 '19 00:01 Paul-RHT

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

JPBTech avatar Sep 29 '19 21:09 JPBTech

I had the same problem. My solution: install this nuget https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Relational/5.0.11?_src=template

fabricioJunior avatar Nov 02 '21 16:11 fabricioJunior