35

After too hastily upgrading to EF 5.0.0.0 RC and being stuck with a .NET 4.5 project that wouldn't deploy to Windows Azure (.NET 4.0 and below), I decided to downgrade to EF 4.3.1.0.

I'm unsure of the best way to perform this type of migration but my strategy is to use "Manage NuGet Packages" identify which projects reference the package, uncheck the package from each project, install the replacement and recheck the correct projects.

Unfortunately, after doing this, my solution produced the titular "FileLoadException".

Could not load file or assembly 'EntityFramework, Version=5.0.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 searched through the solution files particularly packages.config for references to EF 5.0.0.0 RC but could find none.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88

12 Answers12

43

After failed attempts to find references to EntityFramework in repositories.config and elsewhere, I stumbled upon a reference in Web.config as I was editing it to help with my diagnosis.

The bindingRedirect referenced 5.0.0.0 which was no longer installed and this appeared to be the source of the exception. Honestly, I did not add this reference to Web.config and, after trying to duplicate the error in a separate project, discovered that it is not added by the NuGet package installer so, I don't know why it was there but something added it.

<dependentAssembly>
  <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

I decided to replace this with the equivalent element from a working project. NB the references to 5.0.0.0 are replaced with 4.3.1.0 in the following:

<dependentAssembly>
  <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>

This worked!

I then decided to remove the dependentAssembly reference for the EntityFramework in its entirety. It still worked!

I would still be interested in answers to these questions:

  • What added the dependentAssembly for EntityFramework to my Web.config
  • Any consequence(s) of removing these references

I'd be interested to learn.

halfer
  • 19,824
  • 17
  • 99
  • 186
DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • 1
    NuGet can automatically add binding redirects to your project: http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference#Add-BindingRedirect – bricelam Aug 01 '12 at 18:31
  • Thanks @Brice. Will continue my investigation. – DazWilkin Aug 01 '12 at 20:27
  • You can mark your own answer as the correct one, DazWilkin. :) – Jan Aagaard Jan 24 '13 at 07:54
  • Shouldn't the binding be the following one? It is working for me in any case. – Jean-François Beauchamp Jun 12 '13 at 17:09
  • I had this problem, and the issue was that I had made a new console app that by default used .NET 4.5, but I was referencing a domain model project that used .NET 4.0. When I added EF via Nuget to the console app, it imported the latest version for the target .NET, which was EF 5.0. The latest version for .NET 4.0 is EF 4.4, hence the incompatibility. I changed the framework version for the console app, re-added EF, and everything worked! – Alex J Nov 27 '13 at 13:54
21

I have this issue, and all I did was make sure that I was referencing the right .Net framework in all the projects then just change the web.config from

From

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

To

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

All works..

TheAlbear
  • 5,507
  • 8
  • 51
  • 84
5

I had the same issue when updating an older project. Here's what I did to resolve it:

  • Converted all projects to .NET 4.5.
  • Uninstalled the NuGet package for Entity Framework 5.
  • Reinstalled the NuGet package for Entity Framework 5.
  • Cleaned the solution.
  • Rebuilt the solution.

The projects that used Entity Framework 5 and .NET 4 were installing the Entity Framework dll version 4.4. Once I switched the .NET version to 4.5 on the project, the dll version would be 5.

My problem came from older projects being on .NET 4 and a newer project running .NET 4.5 so there were 2 dll versions of EF in my solution.

Hope this helps someone...

Dragn1821
  • 807
  • 2
  • 8
  • 19
4

I had a similar issue running unit tests using MSTEST under Jenkins. The fix in my case was to remove "Version=6.0.0.0, " as shown below:

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

New:
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Culture=neutral, PublicKeyToken=xxxx" requirePermission="false" />

I had to make this change is several App.config and Web.config files in my multi-project solution.

Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54
3

While Building a Project, if in the project properties it shows that it is build under Target.NET Framework 4.5, update it to 4.6 or 4.6.1. Then the build will be able to locate Entity Framework 6.0 in the Web.config file. This approach solved my problem. Selecting Target framework from Project Properties

Jabed
  • 178
  • 1
  • 2
  • 13
2

If you used the Visual Studio 2012 ASP.NET Web Forms Application template then you would have gotten that reference. I'm assuming it's the one you would get via Nuget instead of the framework System.Data.Entity reference.

enter image description here

Robb Vandaveer
  • 1,481
  • 20
  • 25
  • Actually, I just added it via Nuget and it is the same package. As to your other question about what consequences you will get for removing it, so far I've only found that if you're using ASPNET Membership, parts of it will no longer work. – Robb Vandaveer Jan 19 '13 at 01:27
2

I received the exact same error message. Except that my error message said "Could not load file or assembly 'EntityFramework, Version=6.0.0.0...", because I installed EF 6.1.1. Here's what I did to resolve the problem.

1) I started NuGet Manager Console by clicking on Tools > NuGet Package Manager > Package Manager Console 2) I uninstalled the installed EntityFramework 6.1.1 by typing the following command:

Uninstall-package EntityFramework

3) Once I received confirmation that the package has been uninstalled successfully, I installed the 5.0.0 version by typing the following command:

Install-Package EntityFramework -version 5.0.0

The problem is resolved.

Auguste
  • 2,007
  • 2
  • 17
  • 25
1

I had similar issue with selenium: I downgraded my selenium using NuGet and got the same error message. My solution was to remove the newer version lines from the app.config file.

Nir
  • 1,836
  • 23
  • 26
0

I got same issue. I was getting the System.Data.Entity.Infrastructure; error which is only part of v5.0 or later. Just right click the Reference and select "Manage NuGet Package" . In the Installed Package option , uninstall the Entity FrameWork which is already installed and Install the 5.0 version. It solve the problem. I was trying manually get the System.Data.Entity reference , which was not success.

Sujo
  • 1
0
public Configuration()
{
    AutomaticMigrationsEnabled = false;

    // register mysql code generator

    SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}

I find out that connector 6.6.4 will not work with Entity Framework 5 but with Entity Framework 4.3. So to downgrade issue the following commands in the package manager console:

Uninstall-Package EntityFramework

Install-Package EntityFramework -Version 4.3.1

Finally I do Update-Database -Verbose again and voila! The schema and tables are created. Wait for the next version of connector to use it with Entity Framework 5.

Jesse
  • 8,605
  • 7
  • 47
  • 57
0

I had a similar issue:

  1. On my ASP.NET MVC project, I've added a Sql Server Compact database (sdf) to my App_Data folder. VS added a reference to EntityFramework.dll, version 4.* . The web.config file was updated appropriately with the 4.* configuration.

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

  2. I've added a new project to my solution (a Data Access Layer project). Here I've added an EDMX file. VS added a reference to EntityFramework.dll, version 5.0. The App.config file was updated appropriately with the 5.0 configuration

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

On execution, when reading from the database the app always thrown the exception Could not load file or assembly 'EntityFramework, Version=5.0.0.0 ....

The issue was fixed by removing the EntityFramework.dll v4.0 from my MVC project. I've also updated the web.config file with the correct 5.0 version. Then everything worked as expected.

Lucian
  • 3,981
  • 5
  • 30
  • 34
0

In your references click on the EntitiyFramework . Go to properties and set the specific version to False. It worked for me.

Arvin Sanaei
  • 103
  • 1
  • 12