1

I want to use different version of Entity Framework in the same project.? I have two appication: -one with EF5 -and the second with EF6 and reference to first project(those one with ef5)

Now i want to use methods from the first one in the second one. But....

i have problems, with this ,cause when i run method from ef5 app, it says that :

Could not load file or assembly 'EntityFramework, Version = 5.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' or one of its dependencies. Located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

How to use different version of EF dll in the same project?

suggesions?Thanx.

delirek
  • 70
  • 1
  • 6
  • 1
    You need binding redirects. – SLaks Dec 31 '13 at 19:34
  • u mean something like here? http://stackoverflow.com/questions/2460542/using-different-versions-of-the-same-assembly-in-the-same-folder#2461746 – delirek Dec 31 '13 at 19:37
  • 1
    okay, but binding redirection didnt solve my problem. I want to use EF5 and EF6 at the same time- not use EF6 instead EF5 – delirek Dec 31 '13 at 23:46

1 Answers1

4

You cannot load multiple versions of the same assembly into single Application domain. .NET Framework does not support it. You must either use:

  • Use single version of EF in both "applications" - this should be the right way to go if you need to use EF dependent code from the first application in the second one
  • Refactor first application and move all methods you need to reuse into separate assembly not dependent on EF - this should be the right way to go if you can abstract the code from EF
  • Execute code from the first application in separate application domain - don't use this approach. It is like running two ".NET processes" in a single windows process. You have to use inter-process communication to pass data between two application domains.

Normally there is also option for binding redirects but I'm afraid it will not work in this case because EF6 brings too many breaking changes.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Yet another option -- one that I do not recommend, but want to mention for completeness -- is modifying EF6 to give it a distinct assembly name. (It's open source and the license allows it.) –  Aug 01 '15 at 11:20
  • @hvd, that won't work because you'll have a bunch of namespace conflicts – taiji123 Dec 15 '16 at 16:25
  • @taiji123 Only if a single assembly has references to both EF5 and EF6, which isn't the case for the OP. In the OP's case, A has a reference to EF5, so no namespace conflicts. B has a reference to EF6 and to A, but not to EF5 directly, so also no namespace conflicts. –  Dec 15 '16 at 16:50