1

In my current Project i have two Project References that are DataContexts. One is for accessing an Oracle Db and is using EF 4.2. The other is accessing a SQL Server and uses EF 6.0.

I already read this solution, but i can't get it to work.

Here is what i got:

  • I referenced EF 6.0.
  • In a Pre-build command i xcopied both dlls in seperate folders

In my Appconfig i added this:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <codeBase version="6.0.0.0" href="ef6.0\EntityFramework.dll" />
        <codeBase version="4.2.0.0" href="ef4.2\EntityFramework.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

I am still getting: The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Any hints?

Community
  • 1
  • 1
TheJoeIaut
  • 1,522
  • 2
  • 26
  • 59
  • basically you are not targetting the same version of the runtime, that is .Net. Not sure this can be done as some refactoring have been done in assemblies. See http://msdn.microsoft.com/en-us/magazine/jj618295.aspx – tschmit007 Jan 13 '15 at 15:34

1 Answers1

0

The difference to the referenced question/answer is that in the other case there are two DLLs that use different versions of a dependency. In your case, you are trying to use two different versions of a dependency within the same project.

You may try to factor out (wrap) your version-specific code into two DLLs (e.g. OracleDataAccess and SqlDataAccess). In each of those projects you can now reference the specific version of EF. From your main project you then reference the two ...DataAccess projects, and if everything goes well, the dependentAssembly config file entry should resolve the version conflict for the two EF DLLs at runtime.

Note: You might also need to tweak how the EF dependencies are copied to the build directory to match the hrefs in the config file.

Christoph
  • 2,211
  • 1
  • 16
  • 28
  • I think i have something similar to what you say, and it does not work. I have two Data contexts in different class libray projects, EF4 and EF6. a BIZ layer above, two class library projects referencing it´s correspondent DAl layer project. And above all, a single webforms appllication, which has EF4 dependencies registered. when invoking BIZ methods, it is throwinf runtime exception asking for EF6 assemblies. – Ricker Silva Oct 29 '18 at 16:04
  • It doesn't work that way. If you have project A with EF5 and project B with EF6 and when you reference either of those projects from project C, then it will fail because it can't find the EF .dll. – HamsterWithPitchfork May 13 '19 at 12:52