Last post Jul 21, 2016 05:11 PM by dtabako
Jul 20, 2016 03:16 PM|dtabako|LINK
I have a self-hosted SignalR server passing data to a .NET SignalR client. Essentially, it is doing a continuous or on-demand update of a custom type. When I want to trigger an update, I create a data transfer object, load it with the data to send, and send
it via SignalR. The client side captures the update and displays the new values (I have a WPF app and a Console app and both do essentially the same thing - the WPF app just does it a little "prettier"). Everything works fine for most of the properties on
my DTO. But there are two properties that are enum values and those always come across to the client as the enum's 0-value (in my case "Unknown") no matter what I set it to on the server side. On the server side, I trace it all the way to the Clients.All.updateData(data)
call and the DTO (data) has the correct enum values all the way to that point. But putting a breakpoint on the client side right at the point of the function that receives calls from the server, the DTO has incorrect (0) values for both enums. I have searched
online for any possible issues with SignalR serializing enum values and I have not come across anything. Is there something I'm missing? Thanks in advance.
Jul 21, 2016 07:38 AM|Fei Han - MSFT|LINK
According to your description, it seems that something wrong with enum values when data are passed and serialized in SignalR application, could you share us the relevant code?
Besides, this blog explained about serializing Enums in ASP.NET SignalR, you could read it.
Jul 21, 2016 05:11 PM|dtabako|LINK
Thanks! I did see that article and I tried that to no avail. However, after trying many things I think what eventually got it to work was adding setters to my public enum properties. I'm not sure why that is, but if they have setters the enum properties
deserialize properly. If I take the setters off, they do not serialize. If anyone can provide any insight on the "why" of that, I'd certainly like to know. But at least my app does seem to work for now.