SignalR和的WebAPI - 碰撞Newtonsoft.Json引用

问题描述:

我有一个连接到SignalR 2.0后端Windows客户端,现在我想让它连接到的ASP.NET Web API 2.1后端为好。SignalR和的WebAPI - 碰撞Newtonsoft.Json引用

,我使用与Web API通信的库依赖于Newtonsoft.Json 6.0.0.0但Microsoft.AspNet.SignalR.Client 2.0.0.0似乎依靠Newtonsoft.Json 4.5.0.0

由于这是一个Windows客户端,dll文件最终在同一个目录中,并且只有两个需要的版本中的一个最终会在磁盘上结束,这使得信号客户端或HttpClient无法加载它的版本Newtonsoft.Json dll文件。

SignalR错误,如果6 *版在磁盘上:

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, 
    Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its 
    dependencies. The located assembly's manifest definition does not match the 
    assembly reference.(Exception from HRESULT: 0x80131040) 

是否有可能使SignalR使用Newtonsoft的较新版本或者能够在同一个解决方案中使用两个版本?记住

熊,我很新的NuGet包装和SignalR似乎使用隐式引用...

解决方案: 我在signalR客户端库替换版本Newtonsoft参考6.0,并添加装配重定向,如低于基兰Challa写的,到图书馆的App.config以及可执行项目的app.config,现在这两个库查找和加载相同的组件。

Web API & SignalR是参考Json.net的4.5程序集版本构建的。如果您想使用Json.net的6.0版本,则需要在配置文件中添加程序集绑定重定向。

<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-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
+0

谢谢!我取代了6.0版本我signalR客户端库Newtonsoft参考,并添加装配重定向到库的App.config中以及可执行项目的app.config,现在这两个库查找和加载相同的组件。 – MatiasK