[C#] TriggerServerEvent / EventHandler with concrete typed object

Hello,

I’m making a C# ressource / framework and I came across this problematic ExpandoObject/dynamic type. So I made a Shared dll with my entities, just one named User below.

public class User
{
    public int Id { get; set; }
    public string Test { get; set; }
}

The code is very simple on the client side we have a command that triggers when the command /callback is typed but I receive a dynamic or ExpandoObject. So when I want to access a property it is not typed. I tried a soft cast which result in a null reference and a hard (so it throw an exception).

        RegisterCommand("callback", new Action<int, List<object>, string>((source, args, raw) =>
        {
            TriggerServerEvent("eventTestClientCallback", new Action<dynamic>((arg) =>
            {
                Debug.WriteLine($"receive from eventTestClientCallback {arg.Id}, {arg.Test}");
            }));
        }), false);

The server side just send an User with both property set.

    private void eventTestClient([FromSource] Player player)
    {
        User user = new User();
        user.Id = 1;
        user.Test = "woah";

        player.TriggerEvent("playerTest", user);
    }

The thing is that I’d like to have a strongly typed object, a lot of people just say to serialize/deserialize the object with JSON just ot have it typed.

So here are my questions :

  1. Are objects castable somehow without the use of any serializer/deserializer or mapper ?
  2. Is this “feature” worked on or already suggested or impossible to implement ?

Thank you for reading.

If we try to pass an argument into the TriggerServer/TriggerClient we get this error on the other side :

I tried to implement IConvertible but no luck, because when the client receive the object on the other side it becomes a dynamic/Expendo.