Newtonsoft.Json 版本冲突解决

在作asp.net MVC 开发时,由于引用的dll 中使用了更高版本的 Newtonsoft.Json ,致使运行时发生错误,web

查资料说是由于webApi使用了Newtonsoft.Json 致使了,个人项目中没有用到webapi,所以,在Global.asax 中把 下面这行代码屏蔽后,果真再也不报错了。api

 

   //   WebApiConfig.Register(GlobalConfiguration.Configuration);

 

可是,当我在发布该项目时,又遇到了如下错误:app

没法解决“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.0\Blend\Newtonsoft.Json.dll]从新映射到版本“7.0.0.0”[E:\project\.....\Debug\Newtonsoft.Json.dll],以解决冲突并消除警告。
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.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>

虽然该错误并无影响到程序运行,可是我仍是以为不爽,细看说明,原理微软在提示咱们时,就把解决方法告诉了咱们:asp.net

不然,请将如下绑定重定向添加到应用程序配置文件中的“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基本能够兼容,因此问题获得解决。ui

 

推而广之,其余的dll冲突也能够用这种方式解决。spa

相关文章
相关标签/搜索