Referencing multiple versions of the same assembly

孤人 提交于 2019-12-10 12:08:00

问题


Is it possible to have multiple versions of the same strongly named assembly loaded in the same process? There is plenty of similar questions, but non of the answers seem to work.

The reason I'm asking is we need to use newer version (4.0.0.0) of SomeAssembly.dll, but some referenced dlls depend on the older version (3.0.0.0) of this dll.

I have tried using the below assembly binding redirection configuration, but ended up with compilation errors, because my assemblies depend on a newer version of the dll and this configuration is completely overriding the linkage and only version 3.0.0.0 is being used. I would expect this to fail at run-time. Is compiler using the config files here?

Version 4.0.0.0 is referenced in project as per usual. Version 3.0.0.0 is copied to the project output.

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="SomeAssembly" publicKeyToken="123" culture="neutral" />
        <bindingRedirect oldVersion="3.0.0.0" newVersion="3.0.0.0" />
        <codeBase version="4.0.0.0" href="bin/SomeAssembly.dll" />
        <codeBase version="3.0.0.0" href="SomeAssembly.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

回答1:


Try removing line

<bindingRedirect oldVersion="3.0.0.0" newVersion="3.0.0.0" />

and put assemblies in separate folder inside BIN folder. e.g.

<dependentAssembly>
    <assemblyIdentity name="SomeAssembly" publicKeyToken="123" culture="neutral" />
    <codeBase version="4.0.0.0" href="V4\SomeAssembly.dll" />
    <codeBase version="3.0.0.0" href="V3\SomeAssembly.dll" />
  </dependentAssembly>


来源:https://stackoverflow.com/questions/32093712/referencing-multiple-versions-of-the-same-assembly

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