OrleansContrib / SignalR.Orleans

SignalR backend based on Orleans.
MIT License
295 stars 64 forks source link

SendMessage with complex object as arguments does not work #72

Closed kimmccoy closed 5 years ago

kimmccoy commented 5 years ago

When I use the IConnectionGrain.SendMessage to send a simple value type like a string it successfully sends the message to a browser based javascript client.

eg) var message = "hello";
var m = new InvocationMessage(methodName, new[] { message }); await _deviceHubContext.User(id).SendMessage(m); If I send a more complex message it never arrives at the client as verified in chrome dev tools network tab. eg) var message = new { name="fred", age = 10 };
var m = new InvocationMessage(methodName, new[] { message }); await _deviceHubContext.User(id).SendMessage(m);

This does not work.

Is this normal? Is this just me? I suspect I'm doing something wrong. Using SignalR.Orleans v1.2

stephenlautier commented 5 years ago

Almost all our messages are enveloped, meaning they are in complex objects and we never ran into this issue.

Can you try SendSignalRMessage instead as we use that one only, or update to 1.3.0 and there's Send in all grains (User, Group, Client)

kimmccoy commented 5 years ago

I figured it was just me... (newbie to orleans) . But fixed now.

I could use both Send or SendSignalRMessage with either no arguments or a single value type argument like a number and the message was received by the browser client ok.

As soon as I sent a more complex object it would fail to send. Turns out, my complex objects were defined in the same assembly as the grain implementations which in hindsight was silly.

I moved the message types to the grain interface assembly that is shared by the grains, silo and the website with the signalr hubs and it now works. I think signalr in the website was attempting to serialize the complex type but wanted the grains implementation assembly to do so but could not load it of course.

Thanks