14

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=5.0.0.0, 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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath> </Reference> 

What could be a possible root cause?

5
  • Why are you having 3 versions of EF? EF6 alpha2 (6.0.0.0), EF5 for .NET Framework 4.5 (5.0.0.0) and EF 5 for .NET Framework 4 (4.4.0.0). What version do you want to use? If you don't have any other packages - manually remove all references to EntityFramework.dll. If you want to use EF6 remove the reference to System.Data.Entity.dll if you have one. Delete packages.config (if you have other nuget packages you'll break them). Install the EF version you want to use. (I wonder if the mess you end up with was caused by retargeting your project...) Commented Dec 12, 2012 at 5:21
  • I want to be targeting 5, for .net 4.0, which I thought I was, but since I added the 6 alpha briefly everything got messed up. What dll's do I need for ef 4.4? Commented Dec 12, 2012 at 5:30
  • Then clean up your project as I said above but don't remove the reference to the System.Data.Entity.dll. Make sure your project(s) target .NET Framework 4. From Package Manager Console run Install-Updates EntityFramework or use GUI - make sure you are not installing EF6. This should get you EntityFramework.dll 4.4.0.0 which is EF5 for .NET Framework 4. You should also be able to use Uninstall-Package now. When I want to retarget .NET Framework version - I always uninstall EF first, retarget and install EF again to be sure that I have the correct version. Commented Dec 12, 2012 at 5:47
  • very badly stuck in this very same issue! Commented Apr 3, 2014 at 16:39
  • This solved the problem for me: The issue is happening because you might be having multiple versions of entity framework packages used in the project. Refer this: pinfaq.com/93/… Commented Nov 21, 2020 at 8:48

9 Answers 9

18

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a bunch! it seems like, after windows 7 update i get this problem.
There are a few corrections needed to the instructions above. 1) You need to start the Visual Studio tools Command Prompt (usually from the Start menu under your Visual Studio installation men) instead of a general Command Prompt. 5) You do not need to restart Visual Studio in order for the changes to be recognized. Hope it helps...
1

I believe I could figure out a solution. I had several projects in my solution.

enter image description here

My database logic was in SqlDataAccess. The assembly was reference in WebUI.

I started off at the DomainLogic. Define POCOs for repository base classes there.

Then I added SqlDataAccess project.

and tried Enable-Migrations, Add-Migration and Update-Database command. It ran fine. After I added WebUI (an MVC 4 based web application to the project and ran the commands above. I started getting this version error.

I unload the project WebUI and re ran the command. And it ran fine again. So, Even if it's not the best solution you might want to unload other projects leaving the atabase project in the solution and then running these commands. It worked for me. All the best!

Comments

1

I also faced this problem while using using code first migration. just update the entity framework version to Entity Framework Version 6.1.3 to resolve this. using command on Package manager console "Install-Package Entity Framework -version 6.1.3"

Comments

1
  1. Open Manage NUGET Packages for solution... window and update EntityFramework
  2. Restart Visual Studio
  3. Run the command in package manager console Enable-Migrations -ContextTypeName Movie.Models.MovieDBContext(This is a sample context)

Comments

1

Install EF 6.1.3 and this will solve the problem.

Comments

1

Yes above comment is right that worked for me.

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.

C:\Windows\system32>cd.. C:\Windows>cd.. C:\>cd \packages\EntityFramework.5.0.0\lib\net45 C:..\packages\EntityFramework.5.0.0\lib\net45> gacutil /i EntityFramework.dll 

This will definitively works.

Comments

0

Perform the following actions to resolve this issue:

1)Uninstall Entity Framework from the package(Manage NUGET Packages).

2)Restart Visual Studio.

3)Re-install Entity Framework again from package manager.

4)Add reference to the System.Data.Entity.

5)Run the command in package manager console Enable-Migrations -ContextTypeName Movie.Models.MovieDBContext(This is a sample context).

After this you could see the changes reflected in packages.config.

Comments

0

I have Windows 10. The following steps corrected the issue

  1. Open Program and Features and do a search for 'entity'
  2. I noticed an update was installed on 1/23/2016 after the 6.1.3 update on 7/22/2015
  3. Selected the 'Entity Framework 6.1.3' etc.. update
  4. Clicked on the "Repair" button. After the repair completed I restarted Visual Studio and issue no longer surfaced.

Thanks to @Farshid for the initial clue to a resolution.

enter image description here

Comments

-1

I was also facing same error and waste a lot of time on this error **This is only due to I updated entity framework but it gave this error so I again install Entity Framework 6.0.0 ** Error solved

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.