Bit*_*ian 26 c# dependencies json.net nuget socketio4net
我正在尝试使用SocketIO4Net在.net中创建socket.io客户端.看来SocketIO4Net依赖于Newtonsoft.Json> = 4.0.8.我也使用PushSharp库,其Newtonsoft.Json依赖关系> = 4.5.10.当我第一次安装PushSharp时,我得到了NewtonSoft.Json 4.5.11,我认为这个版本也应该支持SocketIO4Net,因为它的版本更高,但每次尝试连接socket.io服务器时都会收到此错误.
无法加载文件或程序集'Newtonsoft.Json,Version = 4.0.8.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
我一直在为这些依赖性问题敲打我的脑袋,如果有人能指出我正确的方向,我将非常感激.
小智 18
找到解决方案,试试:
<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>
Run Code Online (Sandbox Code Playgroud)
您可以修改程序集绑定配置并添加重定向.请参阅在MSDN上重定向程序集版本.
基本上你想添加下面的代码片段到你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>
Run Code Online (Sandbox Code Playgroud)
编辑
为什么需要重定向汇编版本?尽管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版本应该自动添加程序集绑定重定向.
在您的 app/web.config 中放入程序集重定向;
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" PublicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="1.0.0.0-4.5.11.0" newVersion="4.5.11.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
请注意版本号需要与您安装的版本相匹配。
| 归档时间: |
|
| 查看次数: |
43463 次 |
| 最近记录: |