SignalR is sending my struct wrongly

442 views Asked by At

So, after trying to understand whats happens with my messages in a big class... i've found out with a small test that:

public struct Test
{
  public int X {get;set};
  public int Y {get;set};

  public Test(int x, int y)
  {
    X = x;
    Y = y;
  }
}

// hub
var sendMe = new Test(12,20);  
Clients.All.Test(sendMe);

...and client gets Test = (0,0)!

Looks like a big bug. Do i need to fill a bugreport?

1

There are 1 answers

1
Pawel On

I believe this is because JSon.NET (which is used by SignalR client to deserialize payload) does not handle structs by default. You can change your struct to a class.