0
votes

Before you think that this is a duplicated question, well... it maybe but I didn't found useful information anywhere for my issue.

I've a main web application project, let's call it project A and a sub class library project, project B.

Both projects must be compiled with .NET Framework 4 target Framework, and project B has installed Entity Framework Version 6.1.3. Project A instead, has an older Entity Framework 4.3.1...

Forget the "update it" option for this one: quite impossibile, for time due. The problem that I get at runtime is:"

Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies" error when project B is requested by Project A.

I've tried to uninstall EntityFramework on project B, clean the solution, reinstall EntityFramework but the problem still remains. I've tried to downgrade EntityFramework in project B, but I encontered a waste set of problems (edmx xml version mistake,tt namespace generation, metadata trouble, provider troubles...), and for turn back in a "normal" situation, I had to do an SVN revert after that.

Then, I tried to set "specific version = 'True'" on the Entity Framework reference properties in project B, but the error still persists. Don't know if AssemblyBinding in project A could be a part of this problem, but this is the configuration in web.config:

  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
  </dependentAssembly>
</assemblyBinding>

Furthermore, I've noticed when I've reinstalled EF6.1.3 on project B that the bindingRedirect tag was setted with oldVersion="0.0.0.0-6.0.0.0" and newVersion="6.0.0.0", but with that configuration, project A was the one who crashed.

To be more specific, there's a project C class library that uses Entity Framework 5 in this solution and with the assemblyBinding shown, it has no problems... so, what can I do? Any suggestion will be appreciated!

1

1 Answers

0
votes

Made it! Perhaps it's a tricky way, too dirty or don't know.. if you can comment for side effects that would be helpful, but for me this configuration works! Quoting myself:

Don't know if AssemblyBinding in project A could be a part of this problem, but this the configuration in web.config:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" /> </dependentAssembly> </assemblyBinding>

Furthermore, I've noticed when I've reinstalled EF6.1.3 on project B that the bindingRedirect tag was setted with oldVersion="0.0.0.0-6.0.0.0" and newVersion="6.0.0.0", but with that configuration, project A was the one who crashed.

I was so close, but the crash was for this reason: EntityFramework section was registered with 4.4.0.0, and that caused a version conflict in the main project. So, the first step was to declare EntityFramework section with the version 6.0.0.0, but, that wasn't enough because main project couldn't find EF version 6 dll. Infact, the second step is to declare a <codeBase> tag in the assemblyBinding and set an href for the EF6 library. Added the dll on the root of the project, inside a specific folder, and linked it with <codeBase> tag, the second step was completed and every projects in the solution with every version of EntityFrameworks seems to work like a charm!

So, in conclusion:

1) Set EntityFramework section with version 6.0.0.0 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

2) After the creation of a "libs" directory in the project root (or name it whatever you like, same for the position, wherever you like... but it must be reachable) and put the EF 6.0 library there, link it with a <codeBase> tag inside assembly:

<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> <codeBase version="6.0.0.0" href="libs/EntityFramework.dll" /> </dependentAssembly> </assemblyBinding> </runtime>

Known side effects:

  • If you don't want that the library could be downloaded by anyone, remember to restrict access for that libs directory, in the web.config, IIS, or with the most efficient method based on your context

  • The EF6 library under libs is unmanaged by Nuget, so, for future EF upgrades it could be painful to remember what did you do for let this thing work (write it in the technical documentation, comment the web.config, etc...)

I hope that this could be helpful!