17
votes

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.

6
Can you not push the EF library to the server? Do you have EF in the GAC on the server?Justin
Do you have EntityFramework dll in your bin directory ?Shyju
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. Also 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 EF5Pawel
@Justin Sorry, I don't know what GAC is.Splendor
@Shyju Yes, I have EntityFramework.dll in the bin folder.Splendor

6 Answers

15
votes

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

5
votes

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.

5
votes

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

0
votes

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.

0
votes

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")
0
votes

This can happen if your project name conflicts with a nuget package that you referenced. I wasted about 3 hrs before I realized what is going on. So, avoid from entering same name like reference name