简体   繁体   中英

EF-Core Update-Database command fails (cannot load type from Microsoft.EntityFramework.Design 2.1.4.0)

I cannot run my migrations - this is very annoying as I cannot move on with my project...

I think it must be something with ef tooling because some time back (one month) the migrations in this project worked.

The Add-Migration command works successfully, but subsequent Update-Database fail with following error:

Applying migration '20181129154443_strlen'.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
 ---> System.Runtime.Remoting.RemotingException: 
 Cannot load type
 'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler,
 Microsoft.EntityFrameworkCore.Design, Version=2.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Some maybe relevant info:

  • All project in solution depends on same packages (ie. Microsoft.EntityFrameworkCore.Design, Version=2.1.4.0 etc.)
  • Project containing DbContext is using package reference style instead of packages.config (do not ask me why)
  • Startup project is using classic packages.config
  • all projects in solution are targeting .NET framework 4.7.2
  • whole solution builds and runs just fine ( when I remove the pending migrations )
  • Add-Migration command works just fine (generates migration code file, happens for any type of change (does not matter if i am changing column name or add index))
  • I have all of the .NET Core tooling (sdk, runtime) versions installed

There is similar question (unanswered): EF core migration failed: System.Runtime.Remoting.RemotingException: Cannot load type 'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler but none of the suggestions there did not helped me.

What I have tried:

  1. Restart VisualStudio, clean .vs
  2. Cleared all NugetCaches, deleted packages folder
  3. Delete bin/obj folders
  4. Restarted pc
  5. Checked version of NetCore sdk and runtime versions

Solution for me was to convert all of the projects in solution from 4.7.2 to .NET Core 2.2. (also all the NuGets (EFCore, EFCore.Design) were upgraded to v2.2.2). After that the migrations started to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM