引用相同程序集的不同版本的第三方组件 [英] Third party components referencing different versions of the same assembly
问题描述
我无法访问这些组件的源代码。
每个组件都引用了不同版本的同一个DLL程序集log4net。 >
特别是组件A引用了log4net版本1.2.9.0,而组件B引用了log4net版本1.2.10.0。
在VS2012中,我目前正在添加两个第三方组件DLL的引用,我应该添加一个log4net参考。
我试过以下:
1)添加对log4net 1.2.9.0的引用:代码编译,但在运行时我收到异常无法加载文件或程序集[...] log4net ,版本= 1.2.10.0 [...]
2)添加对log4net 1.2.10.0的引用:代码编译,但在运行时我收到异常无法加载文件或程序集[...] log4net,Version = 1.2.10.0 [...]
3)将log4net.dll版本1.2.9.0重命名为log4netOld。 dll并添加版本1.2.9.0和1.2.10.0的项目引用:在编译期间,我得到一个预期的警告,告诉它有命名空间冲突,并且编译器使用1.2.10.0解析类型,所以在运行时我得到与点2 - >代码相同的问题编译,但在运行时我得到异常无法加载文件或程序集[...] log4net,版本= 1.2.10.0 [...]
我是不是所有参考属性的专家,我们当前的所有参考设置是:
1)别名:全局
2)copy local:true
3)嵌入互操作类型:false
我解决问题?
您应该在解决方案中引用1.2.10,并在app.config中添加绑定重定向点1.2.9到1.2.10 - 像这样:
< runtime>
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =log4netpublicKeyToken =1b44e1d426115821culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-1.2.10.0newVersion =1.2.10.0/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>
In my project I'm using two different third party components. I don't have access to the source code of these components.
Each component is referencing a different version of the same DLL assembly log4net.
In particular component A is referencing log4net version 1.2.9.0, while component B is referencing log4net version 1.2.10.0.
In VS2012, I'm currently adding to the references of my project the two third party components DLLs and I should add as well a reference to log4net.
I've tried the following:
1) Adding a reference to log4net 1.2.9.0: code compiles but at runtime I get exception "Could not load file or assembly [...] log4net, Version= 1.2.10.0 [...]"
2) Adding a reference to log4net 1.2.10.0: code compiles but at runtime I get exception "Could not load file or assembly [...] log4net, Version= 1.2.10.0 [...]"
3) Renaming the log4net.dll version 1.2.9.0 to log4netOld.dll and adding both the version 1.2.9.0 and the 1.2.10.0 to the project references: during compile time I get an expected warning telling that there is namespace clash, and the compiler resolves the types using 1.2.10.0, so at runtime I get the same problem as point 2 -> code compiles but at runtime I get exception "Could not load file or assembly [...] log4net, Version= 1.2.10.0 [...]"
I'm not expert at all of the Reference properties, our current setting for all references is:
1) alias: global
2) copy local: true
3) embed interop types: false
Any idea about how can I solve the problem ?
You should reference 1.2.10 in your solution and add a binding redirect in the app.config to point 1.2.9 to 1.2.10 - something like this:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.10.0" newVersion="1.2.10.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
这篇关于引用相同程序集的不同版本的第三方组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!