runliuv

runliuv@cnblogs

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 C# .NET newtonsoft.json 多版本冲突解决,不一致。

 

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

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

 

 

 

方案1:让A、B在运行时,用同一个版本的Newtonsoft.Json.dll。

可以在.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>

 

 方案2:这个告诉程序6.0版本的JSON dll在JSON6文件夹里

多个版本可配置多个路径。

<dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
                <codeBase version="6.0.0.0" href="Json6\Newtonsoft.Json.dll" />
            </dependentAssembly>

这个配置项,诉程序6.0版本的JSON dll在JSON6文件夹里。

--

posted on 2019-04-25 16:44  runliuv  阅读(4147)  评论(0编辑  收藏  举报