zarusz / SlimMessageBus

Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
Apache License 2.0
467 stars 78 forks source link

Error when using JsonMessageSerializer with default settings #252

Closed robert94p closed 4 months ago

robert94p commented 4 months ago

if you use JsonMessageSerializer in web api aplication with default settings, an error is thrown

System.InvalidOperationException: Serializer options cannot be changed once serialization or deserialization has occurred.. at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerOptionsImmutable(JsonSerializerContext context) at System.Text.Json.Serialization.ConverterList.Add(JsonConverter item) at SlimMessageBus.Host.Serialization.SystemTextJson.JsonMessageSerializer..ctor(JsonSerializerOptions options) at SlimMessageBus.Host.Serialization.SystemTextJson.SerializationBuilderExtensions.<>c__DisplayClass0_01.b__1(IServiceProvider svp) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)

https://github.com/zarusz/SlimMessageBus/blob/master/src/SlimMessageBus.Host.Serialization.SystemTextJson/JsonMessageSerializer.cs#L24

zarusz commented 4 months ago

Hello, thanks for reporting, I will have a look here soon.

Are you using the latest version?

robert94p commented 4 months ago

I'm using 2.3.2 version

zarusz commented 4 months ago

@robert94p the issue should be fixed in the 2.3.3 version.

Feel free to re-open the issue if you still run into the error.