Could not load file or assembly 'EntityFramework' after downgrading from 4.5 to 4.0 with EF5

.net asp.net entity-framework

Question

I recently developed a .net 4.5 library using Entity Framework 5. Everything worked fine until I've been told I had to downgrade to .net 4.0 in order to remain compatible with Windows 2003.

I uninstall EF 5 using the Package Manager Console and had the successfull message, then this one:

Failed to generate binding redirects for 'MyProjectName'. An item with the same key has already been added.

The same message appears after downgrading and installation of Entity Framework.

Everything compile. But on execution I've this exception:

The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.

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)":"EntityFramework, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"

In the Web.Config (and App.Config of the libraries) I have those lines:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
...
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"
                      culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
        </dependentAssembly>
   </assemblyBinding>
</runtime>

Any help would be appreciated.

1
6
12/2/2013 11:53:46 AM

Accepted Answer

I finally solved the problem thanks to another topic: could-not-load-file-or-assembly-entityframework-after-downgrading-ef-5-0-0-0

Despite I installed EF 5 package with the Package Manager Console. The actual version of Entity Framework for .Net 4.0 is version 4.4. I've changed the value in config files and it worked!

<section name="entityFramework"
    type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
    Version=4.4.0.0, Culture=neutral, 
    PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
...
<dependentAssembly>
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"
    culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0"/>
</dependentAssembly>
9
5/23/2017 12:10:36 PM

Popular Answer

Use Nuget to uninstall EF then add it again, Clean and rebuild your project.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow