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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With