Json reference conflict in SignalR project

.net, c#, json, json.net, signalr

Solution

Another edge case, if you're using `signalr.exe ghp ...` command to manually generate the javascript files (i.e. for unit testing, etc.), you can get around the issue with a similar work around as the `web.config` answer above.

Just create a regular app.config file (i.e. `signalr.exe.config`) in the same place as `signalr.exe` and place the following contents in it:

<?xml version="1.0"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Problem

Yesterday I began developing a SignalR application - I created 2 different projects (server and client), and everything worked smoothly. Today, I opened it again - and now it is causing problems. This is my client code: ``` signalrHub.client.updateVehicle = function (dbVehicle) { $.each(Vehicles, function() { var vehicle = this; if (vehicle.id == dbVehicle.id && vehicle.dataset == dbVehicle.dataset) { vehicle.move(dbVehicle.latitude, dbVehicle.longitude); } }); }; $.connection.hub.url = "http://localhost:52522/signalr"; signalrHub = $.connection.routeHub; $.connection.hub.start().done(function() { signalrHub.server.joinDataset("JR"); signalrHub.server.getVehicles("JR").done(function (response) { $.each(response.vehicles, function() { Vehicles.push(new Vehicle(this)); }); $.each(Vehicles, function() { this.addToMap(); }); }).fail(function(error) { alert(error); }); }); ``` The fail handler gets called, with the following error: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.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) I've tried updating Newtonsoft.Json to 6.0 - but then I got a compiling error looking for version 4.5. This is the GetVehicles on the server side: ``` public async Task<Vehicles> GetVehicles(string dataset) { var vehicles = await Vehicles.GetData(dataset, DateTime.Today, DateTime.Today.AddDays(1)); Clients.Caller.updateVehicle(vehicles.Data.First()); return vehicles; } ``` and this is the line where it fails: ``` Clients.Caller.updateVehicle(vehicles.Data.First()); ``` If I remove that - the method will execute all the way to the end, and the client times out and never receives the Vehicles object.

Original source