zoukankan      html  css  js  c++  java
  • Assembly Binding redirect: How and Why?

    Assembly Binding redirect: How and Why?

    Why are binding redirects needed at all? Suppose you have application A that references library B, and also library C of version 1.1.2.5. Library B in turn also references library C, but of version 1.1.1.0. Now we have a conflict, because you cannot load different versions of the same assembly at runtime. To resolve this conflict you might use binding redirect, usually to the new version (but can be to the old too). You do that by adding the following to app.config file of application A, under configuration > runtime > assemblyBinding section (see here for an example of full config file):

    <dependentAssembly>
        <assemblyIdentity name="C"  
                          publicKeyToken="32ab4ba45e0a69a1"  
                          culture="en-us" />  
    
        <bindingRedirect oldVersion="1.1.1.0" newVersion="1.1.2.5" />  
    </dependentAssembly>

    You can also specify a range of versions to map:

    <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.2.5" />

    Now library B, which was compiled with reference to C of version 1.1.1.0 will use C of version 1.1.2.5 at runtime. Of course, you better ensure that library C is backwards compatible or this might lead to unexpected results.

    You can redirect any versions of libraries, not just major ones.

    分析:

    比如你使用了Newtonsoft.Json的最新版本11.0,同时你又引用了一个第三方的类库,这个类库引用了一个9.0版本的Newtonsoft.Json 

    那么久必须做bindingRedirect了,否则第三方的类库会找不到9.0的版本。通过bindingRedirect,第三方的类库就可以使用11.0版本的Newtonsoft.Json 

    比如kentico的文件,CMS.DataEngine.dll就依赖于Newtonsoft.Json.dll。

    如果你自己的一个类库,也依赖于Newtonsoft.Json.dll,并且版本不一致

  • 相关阅读:
    XAMPP安装过程中,出现的问题
    Javascript的数据类型和转换
    Vue组件之间的通信
    vue2.0在页面中自定义组件模块,以及页面与组件之间的数据传递
    本地起一个https服务器
    开发人员初始化操作
    添加环境变量
    公钥~gitlab~免密登录
    class继承随笔
    阿里云ECS随笔
  • 原文地址:https://www.cnblogs.com/chucklu/p/12718735.html
Copyright © 2011-2022 走看看