Third party components referencing different versions of the same assembly

我的梦境 提交于 2019-12-08 01:59:25

问题


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 ?


回答1:


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>


来源:https://stackoverflow.com/questions/21699706/third-party-components-referencing-different-versions-of-the-same-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!