MVC框架下出现未能加载文件或程序集“Newtonsoft.Json”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配的错误,
错误截图:
出现这种原因的主要问题就是Newtonsoft.Json引用和Packages.config 和web.Config 中的匹配信息不一致导致的。
解决思路:
1、 在引用下找到Newtonsoft.Json看它的版本信息
看看该信息与Packages.config 和web.Config中对应信息是否一致:
Web中的配置信息
<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>
Packages中的配置信息
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
2、 看看信息是否一致
Web.Config中的配置信息是7.0版本,但是引用中的版本是6.0所以一比较就会发现配置中的版本过高,需要修改为一致。
如<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />