Could not load file or assembly EntityFramework

17

I've deployed an ASP.NET MVC 4 application and the home page loads fine, but when I try to access any other page (which all try to connect to a SQL database) I get this error:

Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I've checked the Web.config file and it has the following relevant entries:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
...
<compilation targetFramework="4.0" />

I've read everything I could find via Google but nothing as helped so far. I know that somehow the version of EF I built the application with is different than the version that's on the deployment machine but I could use some direction in how to correct this difference.

c#
asp.net-mvc
entity-framework
asked on Stack Overflow Jun 3, 2013 by Splendor

5 Answers

15

You seem to be using EF5 on .NET Framework 4 (hence the version 4.4.0.0 in your config file) but the exception you get is talking about EF 4.1 (the version is 4.1.0.0). It seems like some assemblies you are using still try to use 4.1 while the other EF5 (4.4.0.0). Make sure you reference the same assembly everywhere. So, you need to update all the references to use EF5 and rebuild the project. Btw. the entry in the config file is just to point the .NET Framework to a Type that knows how to read the config section so it is not enough to update this to make the app work against EF5

answered on Stack Overflow Jun 4, 2013 by Pawel
5

you can try the following:

in the solution explorer go to the reference node and locate EntityFramework reference node and then in its properties set to False the property Specific Version

then remove the version identifier from your web.config, replace:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

with simply:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false" />

in this way the error related to mismatching versions should b solved.

still like other said in the comments, it is good if you get all your references from NuGet and check-in everything in your source control system.

this approach has worked for me many times for many assembles and does not require any more changes in the web.config when you upgrade to a newer version of the EF later on.

answered on Stack Overflow Jun 3, 2013 by Davide Piras
3

Before going through the fun of updating all the references, try restarting Visual Studio. This resolved the issue for me.

answered on Stack Overflow Feb 14, 2017 by Jay Dawkins
0

I encountered this while trying to debug a project locally on IIS Express.

I manually unloaded the site by opening the the IIS Express options and selecting Stop Site. Then I was able to proceed normally.

answered on Stack Overflow Mar 18, 2016 by Shoe
0

In my case it was a little bit different. The DLLs were completly missing in the GlobalAssemblyCache and were not deployed by VS. I had to deploy the EntityFramework.dll and EntityFramework.SqlServer.dll to GAC, so a GAC Deployment with the following Powershell script worked:

[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
$publish = New-Object System.EnterpriseServices.Internal.Publish            
$publish.GacInstall("C:\Path_To_DLL\EntityFramework.dll")
$publish.GacInstall("C:\Path_To_DLL\EntityFramework.SqlServer.dll")
answered on Stack Overflow Sep 11, 2019 by alex • edited Sep 11, 2019 by alex

User contributions licensed under CC BY-SA 3.0