C# .NET newtonsoft.json 多版本冲突解决

A.DLL 引用了6.0 的 newtonsoft.json  (V2 运行时),

B.DLL 引用了10.0 的 newtonsoft.json (V4 运行时)。

可以在.CONFIG RUNTIME 中加配置 

oldVersion="0.0.0.0-12.0.0.0" newVersion="6.0.0.0" ;

oldVersion 后面的"12.0.0.0" 要大于等于项目中最高版本。

程序根目录 JSON DLL 版本如果是 6.0 的话,修改 newVersion="6.0.0.0" 即可。 (根目的JSON DLL 版本如果是 10.0 ,修改 newVersion="10.0.0.0" 。 根据实际情况修改)
配置项目是大小写敏感的。
配置的作用是让各DLL在运行过程中使用 newVersion="X.0.0.0" (程序根目录) 版本的JSON.DLL ,而不报“未能加载程序集 newtonsoft.json,Version=Y.0.0.0” 的错误。

多运行时混合要加 useLegacyV2RuntimeActivationPolicy="true" 。

--

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  
  
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
          <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

--

原文地址:https://www.cnblogs.com/runliuv/p/10769373.html