Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR & WebApi - colliding Newtonsoft.Json references

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.

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.

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 error if the 6.* version is on disk:

  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)

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

Bear in mind that I am very new to Nuget packaging and the implicit references that SignalR seem to use...

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.

like image 739
MatiasK Avatar asked Feb 11 '14 17:02

MatiasK


People also ask

What is SignalR used for?

SignalR handles connection management automatically, and lets you broadcast messages to all connected clients simultaneously, like a chat room. You can also send messages to specific clients.

What is difference between SignalR and WebSocket?

WebSockets is actually the underlying transport that SignalR uses, at least most of the time. SignalR has the ability to fall back to other ways of transporting messages, such as long-polling over HTTP. This is useful in situations where you don't have WebSockets support.

Is SignalR an API?

Azure SignalR Service provides REST API to support server to client communication scenarios, such as broadcasting. You can choose any programming language that can make REST API call. You can post messages to all connected clients, a specific client by name, or a group of clients.

Does SignalR use WebSockets?

SignalR. ASP.NET Core SignalR is a library that simplifies adding real-time web functionality to apps. It uses WebSockets whenever possible.


1 Answers

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>
like image 121
Kiran Avatar answered Sep 19 '22 03:09

Kiran