Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 551
Francois Stock Avatar asked Dec 01 '13 22:12

Francois Stock


1 Answers

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>
like image 104
Francois Stock Avatar answered Sep 29 '22 07:09

Francois Stock