通过程序包控制台安装Newtonsoft.Json,NuGet会自动加载最新的版本是6.0.8,结果编译程序后出现如下错误:
未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项。系统找不到指定的文件。
原因:asp.net程序引用Newtonsoft.Json会去找Newtonsoft.Json包,如果找不到会默认去引用版本4.5.0.0,这样就产生了冲突。导致整个web程序无法执行,上传到服务器后输入域名会出现一堆的路径列表。
解决方法:
1、通过vs2012:工具→库程序包管理器→程序包管理器控制台→打开控制台执行:PM> install-package newtonsoft.json [项目文件],执行后稍等片刻 Newtonsoft.Json就会加载到相应的项目引用中。
2、保证bin文件夹中有Newtonsoft.Json包
3、在webconfig文件中添加:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
这样保证程序加载最新的包版本6.0.0.0
4.重新编译