首页 > 技术文章 > 解决未能加载文件或程序集“Newtonsoft.Json ...."或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)

loyung 2016-11-28 13:07 原文

今天遇到了一个比较坑的问题,琢磨了好久。。。

因为需要引用一个第三方的类库,三方的类库引用的是Newtonsoft.Json.dll 版本7.0.0而我的项目中引用的是Newtonsoft.Json.dll 版本4.5.0,这样两个引用造成了冲突。所有的引用都OK,编译时提示“ Newtonsoft.Json.Linq”未引用,可是这明明已经引用了。尝试使用nuget更新,更新到最新版9.0.0,更新成功后可以一成功编译,但是访问时又出现这个样的问题。

最终解决方法,修改web.config,这里只是告诉大家格式,只用添加完整的dependentAssembly内容即可。

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

 

推荐阅读