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.
ASP.NET Core SignalR supports two protocols for encoding messages: JSON and MessagePack.
SignalR supports full duplex communication that allows the client and server to transfer data back and forth.
The default keepalive timeout period is currently 20 seconds. If your client code tries to call a Hub method while SignalR is in reconnecting mode, SignalR will try to send the command.
SignalR Hubs are a way to logically group connections as documented. Take an example of a chat application. A group of users could be part of the same hub which allows for sending messages between users in the group. The hubName here can be any string which is used to scope messages being sent between clients.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With