zoukankan      html  css  js  c++  java
  • Newtonsoft.Json 版本冲突解决

    在做asp.net MVC 开发时,因为引用的dll 中使用了更高版本的 Newtonsoft.Json ,导致运行时发生错误,

    查资料说是因为webApi使用了Newtonsoft.Json 导致了,我的项目中没有用到webapi,因此,在Global.asax 中把 下面这行代码屏蔽后,果然不再报错了。

       //   WebApiConfig.Register(GlobalConfiguration.Configuration);

    但是,当我在发布该项目时,又遇到了以下错误:

    无法解决“Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”与“Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”之间的冲突。正在随意选择“Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”。
    1>  请考虑使用 app.config 将程序集“Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”从版本“4.5.0.0”[D:Program Files (x86)Microsoft Visual Studio 12.0BlendNewtonsoft.Json.dll]重新映射到版本“7.0.0.0”[E:project.....DebugNewtonsoft.Json.dll],以解决冲突并消除警告。
    1>C:Program Files (x86)MSBuild12.0inMicrosoft.Common.CurrentVersion.targets(1635,5): warning MSB3247: 发现同一依赖程序集的不同版本间存在冲突。在 Visual Studio 中,请双击此警告(或选择此警告并按 Enter)以修复冲突;否则,请将以下绑定重定向添加到应用程序配置文件中的“runtime”节点: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /></dependentAssembly></assemblyBinding>

    虽然该错误并没有影响到程序运行,但是我还是觉得不爽,细看说明,原理微软在提示我们时,就把解决方法告诉了我们:

    否则,请将以下绑定重定向添加到应用程序配置文件中的“runtime”节点:
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /></dependentAssembly>
    </assemblyBinding>
    

     意思是,把上面这串xml 代码放到runtime 节点里,把用到0.0.0.0-7.0.0.0 版本的dll 的地方,全部重新定位到7.0.0.0 版本,因为这个dll基本可以兼容,所以问题得到解决。

    推而广之,其他的dll冲突也可以用这种方式解决。

  • 相关阅读:
    事务
    触发器
    入行大数据必须知道的事!
    5G如何使云计算更加前卫
    2021年加密货币和区块链风向
    2020年数据存储管理发生的7种变化
    如何克服物联网中数据集成的挑战
    从开发到产出:关于机器学习的七则干货建议
    如何利用机器学习进行静态分析
    AI如何改变DevOps?
  • 原文地址:https://www.cnblogs.com/NewBigLiang/p/5371745.html
Copyright © 2011-2022 走看看