elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
5.87k stars 1.06k forks source link

[BUG] Need to clone serializer to adjust options for context #5277

Closed jdevillard closed 2 weeks ago

jdevillard commented 2 weeks ago

Description

In the API, regarding the context of the Request, we need to adjust the Converters available in the Serializer and so we need to clone the serializer before.

otherwise this will throw an exception :

System.InvalidOperationException: This JsonSerializerOptions instance is read-only or has already been used in serialization or deserialization.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerOptionsReadOnly(JsonSerializerContext context)
   at System.Text.Json.JsonSerializerOptions.ConverterList.OnCollectionModifying()
   at System.Text.Json.Serialization.ConfigurationList``1.Add(TItem item)

Related Issues

related to #5275 related to #5144