“无法加载文件或程序集“Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或其某个依赖项。找到的程序集清单定义与程序集引用不匹配。(HRESULT异常:0x80131040)”
我已经整整一天都在解决这些依赖问题,如果有人能指点我正确的方向,我将非常感激。
找到解决方案,请尝试以下方法:
<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>
app.config
或web.config
文件中:<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<!--
Assembly versions can be redirected in application,
publisher policy, or machine configuration files.
-->
<bindingRedirect oldVersion="1.0.0.0-4.5.11.0" newVersion="4.5.11.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
编辑
为什么需要重定向程序集版本?尽管SocketIO4Net支持新版本的Newtonsoft.Json,但它是针对单个版本(在您的情况下为4.0.8)进行编译的。此版本存储在DLL中,并用于加载SocketIO4Net所依赖的DLL。
请注意,NuGet依赖项与DLL/运行时依赖项不同 - 对Newtonsoft.Json >= 4.0.8的NuGet依赖项仅意味着您可以将SocektIO4Net安装到具有较新版本Newtonsoft.Json的项目中,它与运行时设置无关。
话虽如此,如果您的项目具有app.config或web.config文件,则最近的NuGet版本应自动为您添加程序集绑定重定向。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
但最好检查一下它是否是最新版本。在我的情况下,Newtonsoft.JSON(v.6.0.4) 已经依赖于另一个软件包。
有两个选择;
最后的建议,如果你正在使用多个项目,比如 exe-dll,并检查其中是否有 Newtonsoft.JSON 的版本。
遇到了同样的问题。
刚刚解决了。
NuGet 用于安装 Ext.NET 后出现了这个问题,它依赖于 Newtonsoft.JSON。
在 /bin 文件夹中已经有一个 Newtonsoft.JSON.dll 文件(显然 web.config 文件中也有对它的引用),而我在调试时开始了 NuGet Package-Install 过程,没有检查文件是否被锁定。
运行时错误窗口会告诉您堆栈跟踪中哪部分清单出现了问题,我的是主版本,所以我检查了安装包版本。它的主版本相差1个版本。在 "[物理路径]/../packages/Newtonsoft.Json.[版本]/lib/[.net 版本]/" 下找到了原始的 NuGet 文件。
Manifest 和 Library 都在那里,所以将它们复制到 /bin 文件夹中,更新根 web.config 的程序集信息,就可以解决问题了。
示例代码:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
之后
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" PublicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="1.0.0.0-4.5.11.0" newVersion="4.5.11.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="" culture="neutral"/>
<codeBase version="3.0.0.0" href="bin\Newtonsoft_Old\Newtonsoft.Json.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<codeBase version="4.5.0.0" href="bin\Newtonsoft.Json.dll" />
</dependentAssembly>
其他解决方案对我没有用。尽管我有不同的Nuget包(Newtonsoft.Json.Schema版本=3.0.0.0)。
所以我的项目是一个ASP .NET项目,而Newtonsoft.Json.Schama包被引用在一个.NET Standard项目中。解决方案很简单,只需将Nuget包添加到WEB(或启动)项目中,问题就会消失。
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
删除可能指向packages.config上一个版本的先前行。
删除packagers目录中旧版本的目录。
删除NewtonSoft.Json的引用并重新添加它,指向最新版本。
根webconfig将有以下内容:
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
完成所有操作后,关闭并重新打开Visual Studio。
这应该可以解决问题。
我在安装PM> install-package durandal.starterkit时遇到了同样的错误。
我使用了以上方法来解决。