问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/21708912/signalr-webapi-colliding-newtonsoft-json-references