locked
SignalR Serializing enum values RRS feed

  • Question

  • User499062300 posted

    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.

    Dennis

    Wednesday, July 20, 2016 3:16 PM

Answers

  • User499062300 posted

    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.

    Dennis

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 21, 2016 5:11 PM

All replies

  • User61956409 posted

    Hi Dennis,

    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.

    http://serena-yeoh.blogspot.sg/2014/04/serializing-enums-in-aspnet-signalr.html

    Best Regards,

    Fei Han

    Thursday, July 21, 2016 7:38 AM
  • User499062300 posted

    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.

    Dennis

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 21, 2016 5:11 PM