nats.net icon indicating copy to clipboard operation
nats.net copied to clipboard

Can't serialize System.Object

Open wf-soft opened this issue 6 months ago • 1 comments

Observed behavior

Everything is normal when I use the console, but there is an error when using AddNats

services.AddNats(configureOpts: opt => opt with
{
    Url = "nats://localhost:4223"
});

Expected behavior

serialization

Server and client version

2.12.0

Host environment

No response

Steps to reproduce

services.AddNats(configureOpts: opt => opt with
{
    Url = "nats://localhost:4223"
});
await foreach (NatsMsg<object?> msg in nc.SubscribeAsync<object?>("foo.*.*"))
{
    Console.WriteLine($"Received {msg.Subject}: {msg.Data}\n");
}
await nc.PublishAsync("foo.0.0", new { Test = TestEnum.None });

wf-soft avatar Oct 15 '25 08:10 wf-soft

It should work if you use AddNatsClient() extension rather. there are two DI packages, one is geared towards AOT so it won't serialize ad hoc JSON by default.

mtmk avatar Oct 15 '25 09:10 mtmk