6

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.

Francois Stock
  • 685
  • 1
  • 9
  • 17

2 Answers2

9

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>
Community
  • 1
  • 1
Francois Stock
  • 685
  • 1
  • 9
  • 17
  • And the other part of the issue was entity framework 4.0 is shipped with .net and 5.0 was decoupled from .net and available as a nuget package – Mike Beeler Dec 02 '13 at 12:42
  • 2
    in case anyone is digging around http://stackoverflow.com/questions/12168035/entity-framework-5-0-minimum-net-framework-version-required-net-4-0-or-4-5 – phil soady Dec 02 '13 at 12:54
  • And if you specifically ask package manager to install EF 4.4, it tells you that this version doesn't exist. – Francois Stock Dec 02 '13 at 14:19
0

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

Juano
  • 63
  • 1
  • 10