不同的EntityFramework版本在同一个解决方案 [英] Different EntityFramework versions in same solution

查看:209
本文介绍了不同的EntityFramework版本在同一个解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧的Silverlight应用程序使用EF5,不能升级到EF6。我有另一个项目使用EF6与不同的上下文,但我得到:


无法加载文件或程序集EntityFramework,版本= 6.0 .0.0,
Culture = neutral,PublicKeyToken = b77a5c561934e089'或其
依赖关系之一。找到的程序集的清单定义不是
匹配程序集引用。 (HRESULT的异常:0x80131040)


我假设这是因为EF5已经加载(它在主项目中,请问我为什么),它仍然指向 dll 而不是EF6。我如何得到这个工作?



我补充说:

  <运行时间> 
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =EntityFrameworkpublicKeyToken =b77a5c561934e089culture =neutral/>
< codeBase version =5.0.0.0href =C:\Projects\project\2.1.1EF2\packages\EntityFramework.5.0.0\lib\\\
et45\EntityFramework。 DLL/>
< codeBase version =6.0.0.0href =C:\Projects\project\2.1.1EF2\packages\EntityFramework.6.1.0\lib\\\
et45\EntityFramework。 DLL/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>

到我的主要web.config以下lgos建议,但现在我收到:


{[A] System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection不能转换为[B] System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection 。类型A源自'EntityFramework,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089',位置'C:\Windows\Microsoft.NET\Framework\v4.0.30319\\ \\ Temporary ASP.NET Files\project211ef\97babe28\e7ea3fa9\assembly\dl3\01275099\70646f08_d86ecf01\EntityFramework.dll'。类型B源自'EntityFramework,Version = 6.0.0.0,Culture = neutral ,PublicKeyToken = b77a5c561934e089'在位置'C:\Projects\project\2.1.1EF2\packages\EntityFramework.6.1.0\lib\\\
et45\EntityFramework.dll'的上下文'默认'。 }


尽管访问了EF6实体部分,它仍然试图使用EF5。



我通过添加绑定重定向来解决这个问题。在主要的 web.config 我重定向到新版本,然后在一个子 web.config 重定向到旧版本

解决方案

通过在配置文件中定义程序集绑定,可以在同一应用程序中使用两个不同版本的程序集。我认为这个 answer 应该帮助你。


I have an old Silverlight application that uses EF5 and can't be upgraded to EF6. I have another project that uses EF6 with a different context, but I get:

Could not load file or assembly 'EntityFramework, Version=6.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)

I'm assuming this is because EF5 is already loaded (it's in the main project, don't ask me why) and it's still pointing to that dll instead of the EF6 one. How can I get this to work?

I added:

   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <codeBase version="5.0.0.0" href="C:\Projects\project\2.1.1EF2\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll"/>
        <codeBase version="6.0.0.0" href="C:\Projects\project\2.1.1EF2\packages\EntityFramework.6.1.0\lib\net45\EntityFramework.dll"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

to my main web.config following lgos suggestion, but now I receive:

{"[A]System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection cannot be cast to [B]System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection. Type A originates from 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\project211ef\97babe28\e7ea3fa9\assembly\dl3\01275099\70646f08_d86ecf01\EntityFramework.dll'. Type B originates from 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'Default' at location 'C:\Projects\project\2.1.1EF2\packages\EntityFramework.6.1.0\lib\net45\EntityFramework.dll'."}

It looks like it's still trying to use EF5, despite it accessing the EF6 entity section.

I fixed this by adding binding redirects. In the main web.config I redirect to the new version then in a sub web.config redirect to the old version.

解决方案

It's possible to use two different versions of assembly in the same applications by defining assembly binding in config file. I think this answer should help you.

这篇关于不同的EntityFramework版本在同一个解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆