升级webapi依赖的Newtonsoft.json的版本(转)

随着微软日渐重视开源社区的贡献,微软在自己的产品中往往也会集成开源的第三方库。 比如System.Net.Http.Foramatting.dll 就依赖于Newtonsoft.json v4.5. 所以如果你项目的Newtonsoft.json的版本高于v4.5。当调用System.Net.Http.Foramatting库中关于json的 功能就会出现如下异常:

解决方法很简单:在config文件中加入如下配置,用于替换7.5版本以下的Newtonsoft.json到8.0版本。

复制代码
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
        <bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="8.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
复制代码

该方法同样适用于其他第三方库的更新。

原文地址:https://www.cnblogs.com/tianboblog/p/5486550.html