编程语言
首页 > 编程语言> > c#-.net引用库的不同版本的麻烦

c#-.net引用库的不同版本的麻烦

作者:互联网

我有F#(C#我认为也一样)项目A,它引用了版本3.4的QuickGraph库.在项目B中使用的A引用了现代QuickGraph 3.6.在B的app.config中:

 <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="QuickGraph" publicKeyToken="f3fb40175eec2af3" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.6.61114.0" newVersion="3.6.61114.0" />
      </dependentAssembly>
    </assemblyBinding>    
 </runtime>

其作品.外部项目C在运行时B中加载.当调用A的某些方法时,我收到IO错误:无法加载QuickGraph库的3.4版.

Project C不是我的项目,我无法重新编译它.我应该怎么做才能避免这个错误?谢谢!

解决方法:

该问题称为“依赖关系地狱”.

来自MSDN的解决方案:

If you have multiple versions of an assembly in a directory and you
want to reference a particular version of that assembly, you must use
the element instead of the privatePath attribute of the
element. If you use the element, the runtime stops
probing the first time it finds an assembly that matches the simple
assembly name referenced, whether it is a correct match or not. If it
is a correct match, that assembly is used. If it is not a correct
match, probing stops and binding fails.

或者,您可以使用AppDomain.AssemblyResolve事件来解析要使用的程序集.

标签:f,c,net
来源: https://codeday.me/bug/20191108/2010430.html