Entity Framework code first migrations throwing error

c#-4.0 database-migration ef-code-first entity-framework


Here is what I did before I got this error:

  1. Installed EF (the pre release version, 6 maybe, I dunno)
  2. decided I did not want, so uninstalled that and reinstalled the stable version (5)
  3. Truncated my database via SSMS

here is the error:

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or      
assembly 'EntityFramework, Version=, Culture=neutral, PublicK
eyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest   
definition does not match the assembly reference. (Exception from H
RESULT: 0x80131040)"
At C:\Projects\BCATracker.Web\packages\EntityFramework.6.0.0- 
alpha2\tools\EntityFramework.psm1:425 char:31
+     $domain.CreateInstanceFrom <<<< (
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation

Here is what I have tried:

  • Delete everthing from the bin directory, rebuild.
  • remove EF from nuget, delete the file in the packages directory, readd ef in nuget.

Looking at the proj file I see this:

<Reference Include="EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">

What could be a possible root cause?

7/15/2018 10:08:34 AM

Popular Answer

I figured out the problem. EntityFramework.dll needed to be in the GAC for Visual Studio to use it from the package manager.

  1. Start Visual Studio Command Prompt (ensure you started Visual Studio as Administrator)
  2. Go to your packages directory and find the EntityFramework package directory.
  3. Go to lib\net45 (if targeting 4.5)
  4. type: gacutil /i EntityFramework.dll

Note: It may be wise to restart the computer entirely at this point.

I'm not sure why Visual Studio stopped seeing the DLL, but this got me past this problem.

4/29/2016 9:22:29 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow