Efcore: Migrations looking for invalid netstandard version after update to EF 3.0

Created on 29 Oct 2019  路  15Comments  路  Source: dotnet/efcore


Recently updated asp.net core project to netcoreapp 3.0 and updated Microsoft.EntityFramework.* to 3.0.0

Everything is working as expected, all tests are passing and production instances are all stable... however.

Any dotnet ef * command produces the following output

System.IO.FileLoadException: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
   at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
   at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)
   at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()
   at Microsoft.EntityFrameworkCore.Tools.Commands.DatabaseUpdateCommand.Execute()
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)


Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I have no global.json anywhere in my tree, I have dotnet-sdk 3.0, 2.2 & 2.1 intalled. I have audited my dependencies as much as I can (this is a large multi-project solution with a large number of dependencies) to ensure they are all up to date (dotnet outdated shows clean, NuGet package manager in VS shows no updates). I'm filing this as a bug as I have put close to 10 hours into this now and I'm out of ideas, I'm happy to accept that there is something wrong in my dependency graph but this really shouldn't be this hard? Especially given that I'm not running any preview packages, everything is RTM.

Further technical details

(showing output from my Ubuntu box, behaviour is exactly the same on my Windows box)

dotnet --info   
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  19.10
 OS Platform: Linux
 RID:         ubuntu.19.10-x64
 Base Path:   /usr/share/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  95a0a61858

.NET Core SDKs installed:
  2.1.802 [/usr/share/dotnet/sdk]
  2.2.402 [/usr/share/dotnet/sdk]
  3.0.100 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

area-migrations area-tools customer-reported punted-for-5.0 type-bug

Most helpful comment

Thanks for getting involved @ajcvickers and @bricelam, I tried to put together a minimal repro over the weekend, and along the way discovered the issue was that I now need the below in the csproj file of the project which contains my migrations.

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
</PackageReference>

All 15 comments

@fergalmoran Did you install dotnet-ef as a global tool? (This was not needed prior to 3.0.)

@ajcvickers Yes I did. I installed every 3.* version of it I could find both on my development boxes and on clean Win & Ubuntu boxes.

I don't want to be a pain but this is becoming a really serious issue for us, we're completely stalled here as we can't add any new features while this is broken, I'm sure I'm missing something simple or being a complete idiot but I would be extremely grateful for any guidance you can provide.

@bricelam Any ideas here?

I'd need a repro do dig into it. The full --verbose output might be helpful too.

Thanks for getting involved @ajcvickers and @bricelam, I tried to put together a minimal repro over the weekend, and along the way discovered the issue was that I now need the below in the csproj file of the project which contains my migrations.

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
</PackageReference>

@bricelam Should we update the breaking change docs to include that you may now need an explicit package reference for Design in your Migrations project?

I'd need a full repro to fully understand what's going on here. I don't see how the error and fix are at all related.

@fergalmoran Can you post the repro solution that you created that works without the package reference on an earlier version of EF Core?

@bricelam @ajcvickers - 100% adding the above 4 lines to my migrations project fixed the issue, I even removed and re-added to double check. It's late here now but I'll try to put together a minimal repro tomorrow for you (I gave up on creating the repro once I stumbled upon the fix).

Adding the explicit package reference did not fix the problem for me, still the same error occures.

I have some ideas about this. Let me experiment. But a repro would also be great if you have one

I try to create a minimal one.

Found the root of the problem, i had the following line in my .csproj
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>

Edit: It can be reproduced with following repo, if you add the line above to the project file: gatno/ef_test

Dotnet Info

dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.101
 Commit:    b377529961

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.101/

Host (useful for support):
  Version: 3.1.1
  Commit:  a1388f194c

.NET Core SDKs installed:
  2.2.100 [/usr/share/dotnet/sdk]
  3.1.101 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

dotnet ef

dotnet ef

                     _/\__       
               ---==/    \\      
         ___  ___   |.    \|\    
        | __|| __|  |  )   \\\   
        | _| | _|   \_/ |  //|\\ 
        |___||_|       /   \\\/\\

Entity Framework Core .NET Command-line Tools 3.1.1

Usage: dotnet ef [options] [command]

Options:
  --version        Show version information
  -h|--help        Show help information
  -v|--verbose     Show verbose output.
  --no-color       Don't colorize output.
  --prefix-output  Prefix output with level.

Commands:
  database    Commands to manage the database.
  dbcontext   Commands to manage DbContext types.
  migrations  Commands to manage migrations.

Use "dotnet ef [command] --help" for more information about a command.

Hi I get te same issue but am trying to run the migration with the following that I got from here (and modified - seems `--content-root`` is depicted in 3.1.1.

#!/bin/bash
set -x
EfMigrationsNamespace=$1
EfMigrationsDllName=$1.dll
EfMigrationsDllDepsJson=$1.deps.json
DllDir=$PWD
EfMigrationsDllDepsJsonPath=$PWD/$EfMigrationsDllDepsJson
PathToNuGetPackages=$HOME/.nuget/packages
PathToEfDll=$HOME/.dotnet/tools/.store/dotnet-ef/3.1.1/dotnet-ef/3.1.1/tools/netcoreapp3.1/any/tools/netcoreapp2.0/any/ef.dll

dotnet exec --depsfile ./$EfMigrationsDllDepsJson --additionalprobingpath $PathToNuGetPackages $PathToEfDll database update --assembly ./$EfMigrationsDllName --startup-assembly ./$EfMigrationsDllName --project-dir .  --data-dir $DllDir --verbose --root-namespace $EfMigrationsNamespace

I get this

 + EfMigrationsNamespace=MyAssembly.
08:12:00
  + EfMigrationsDllName=MyAssembly..dll
08:12:00
  + EfMigrationsDllDepsJson=MyAssembly.deps.json
08:12:00
  DllDir=...
08:12:00
EfMigrationsDllDepsJsonPath=/opt/buildagent/work/37693b6f921d32c5/TenantDBMigration/Output/TenantDBMigration.deps.json
  PathToNuGetPackages=/root/.nuget/packages
 PathToEfDll=/root/.dotnet/tools/.store/dotnet-ef/3.1.1/dotnet-ef/3.1.1/tools/netcoreapp3.1/any/tools/netcoreapp2.0/any/ef.dll
 dotnet exec --depsfile ./MyAssembly.deps.json --additionalprobingpath /root/.nuget/packages /root/.dotnet/tools/.store/dotnet-ef/3.1.1/dotnet-ef/3.1.1/tools/netcoreapp3.1/any/tools/netcoreapp2.0/any/ef.dll database update --assembly ./MyAssembly.dll --startup-assembly ./MyAssembly.dll --project-dir . --data-dir ... --verbose --root-namespace myNamespace
  Using assembly 'MyAssemby'.
  Using startup assembly 'MyAssembly'.
  Using application base '....
  Using working directory '...'.
  Using root namespace 'myNamespace'.
  Using project directory '.'.
  Using data directory '...'.
  System.IO.FileLoadException: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  File name: 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
     at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
     at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

I just run into this issue when upgrading a 2.2 project to 3.1.

An over simplified example of the structure was:

  • MyApp.Platform (had the Design ref)

    • Contained the Design nuget reference

  • MyApp.Server

    • References MyApp.Platform

    • Contains the DbContext & Migrations

Moving the Design reference to the project that contains the Migrations (i.e. MyApp.Server) resolved the issue. I did not need to add the explicit reference like @fergalmoran mentioned:

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
</PackageReference>

The following was sufficient to resolve the issue:

<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3" />
  </ItemGroup>
Was this page helpful?
0 / 5 - 0 ratings