Newtonsoft.Json 多版本并存解决未能加载文件或程序集

Newtonsoft.Json 这个程序集是非常讨厌的,特别是对一些比较老的系统要加新功能的时候,往往会出现引用到多个版本的情况,编译或者运行的过程中会出现 未能加载文件或程序集“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项 之类的错误。
解决方式是让多个版本的 Newtonsoft.Json 并存。
比如 V6和V12版本的并存:
V6版本dll 复制到Bin/Newtonsoft.Json.6/Newtonsoft.Json.dll
V12版本dll 复制到Bin/Newtonsoft.Json.12/Newtonsoft.Json.dll

修改 Web.config 或者 App.config,注意旧版的 publicKeyToken值为 null,不能留空

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="null" />
        <codeBase version="6.0.0.0" href="Bin/Newtonsoft.Json.6/Newtonsoft.Json.dll" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <codeBase  version="12.0.0.0" href="Bin/Newtonsoft.Json.12/Newtonsoft.Json.dll" />
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
    </dependentAssembly>
</assemblyBinding>

</runtime>

参考:https://www.cnblogs.com/andyaicao/p/9935111.html

Newtonsoft.Json

我来吐槽

*

*