I have an asp-hosted webasenbly on blazor using SignalR to send data from the server to the client. Here's the server sending a card to the client:
FounderCard cardToSend = LinkedInCards.GetOne();
int ReaminigCards = LinkedInCards.Count;
cardToSend.IsLeaderOfBand= true;
cardToSend.IsSelected = true;
await Hub.Clients.All.SendAsync(MessageOrders.RevealLinkdinCard.ToString(), cardToSend, ReaminigCards);
here's the debug when sending the object, clearly properly filled in:
Here's the receiving client:
hub.On<FounderCard, int>(MessageOrders.RevealLinkdinCard.ToString(), (card, remainig) => {
Game.RevealLinkedinCard(card, remainig);
});
But the object is anew. The values on the enums are the 0 value..
PS: the method work for other complex structures as player data, all fields arrive properly formatted to the destination ...
Just in case it helps, this is the definition of the FounderCard being sent:
public class FounderCard : Card
{
//base clase Card just implements Serialize and INotifyPropertyChanged
public Sections Section;
public Races Race;
public string Color => FounderCommons.FromSectionToColor(this.Section);
public string ID = String.Empty;
public bool IsLeaderOfBand;
public bool IsSelected;
public void SetID(int counter)
{
this.ID = FounderCommons.GetSectionID(this.Section) + "_" + FounderCommons.GetRaceID(this.Race) + "_" + counter.ToString();
}
}
System.Text.Json (the Json library being used by default in SignalR), doesn't serialize fields by default. You either need to change the fields to properties by adding { get; set; }
, or you can set the attribute [JsonInclude]
on the fields. More info can be found at https://learn.microsoft.com/dotnet/standard/serialization/system-text-json-how-to?pivots=dotnet-6-0#include-fields