SignalR&安培;的WebAPI - 碰撞Newtonsoft.Json引用 [英] SignalR & WebApi - colliding Newtonsoft.Json references

查看:664
本文介绍了SignalR&安培;的WebAPI - 碰撞Newtonsoft.Json引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到SignalR 2.0后端​​Windows客户端,现在我想使它连接到的ASP.NET Web API 2.1后端为好。

I have a windows client that connects to a SignalR 2.0 back-end, now I am trying to make it connect to a ASP.NET Web API 2.1 back-end as well.

这是我使用的网络API进行通信的库依赖于 Newtonsoft.Json 6.0.0.0 但Microsoft.AspNet.SignalR.Client 2.0.0.0似乎依靠的 Newtonsoft。 JSON 4.5.0.0

The library that I use to communicate with the web api relies on Newtonsoft.Json 6.0.0.0 but the Microsoft.AspNet.SignalR.Client 2.0.0.0 seems to rely on Newtonsoft.Json 4.5.0.0.

由于这是一个Windows客户端的dll文件,结束了在同一目录中,只有两个所需的版本之一将结束在磁盘上,使得无论是signalr客户端或HttpClient的无法加载其Newtonsoft版本以.json dll文件。

Since this is a windows client the dll-files end up in the same directory and only one of the two required versions will end up on disk, making either the signalr-client or the HttpClient fail to load its version of the Newtonsoft.Json dll file.

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的较新版本或能够在同一溶液中同时使用这两种版本

Is it possible to make SignalR use the newer version of Newtonsoft or to be able to use both versions in the same solution?

请记住,我是很新的的NuGet包装和含蓄地提及了SignalR似乎使用...

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

Solution: I replaced the Newtonsoft reference in my signalR client library with version 6.0, and added the assembly redirect, as written below by Kiran Challa, to the library's App.config as well as the app.config of the executable project, now both libraries look for and load the same assembly.

推荐答案

网络API和放大器; SignalR建成参考Json.net..if 4.5程序集的版本,你想使用6.0版本Json.net,你将需要添加一个程序集绑定重定向配置文件。

Web API & SignalR were built with reference to 4.5 assembly version of Json.net..if you would like to use 6.0 version of Json.net, you would need to add an assembly binding redirect in your configuration file.

<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>

这篇关于SignalR&安培;的WebAPI - 碰撞Newtonsoft.Json引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆