Hello @Lauris Vonogs
This issue you mentioned could be related to the change in serialization from Newtonsoft.Json
to System.Text.Json
, as mentioned in this page (https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-dotnet-isolated-overview). When you try to return a list that contains exceptions with inner exceptions from the Activity Function to the Orchestration Instance, which were created with 2 arguments (message and innerException), the function fails with the error message System.Text.Json.JsonException: The JSON value could not be converted to System.Collections.Generic.List1[System.Exception].
This issue doesn't happen when you try to pass only message (1 argument) to the Exception and it didn't happen also when using .Net 6.0 in-process model.
One workaround for this issue is to create a custom serializer that can handle the serialization of exceptions with inner exceptions.
You can implement the IErrorSerializerSettingsFactory
interface to create a custom JsonSerializerSettings
object that can handle the serialization of exceptions with inner exceptions. Here is an example of how to implement this interface:
internal class CustomErrorSerializerSettingsFactory : IErrorSerializerSettingsFactory
{
public JsonSerializerSettings CreateJsonSerializerSettings()
{
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, Converters = { new ExceptionConverter() } };
return settings;
}
}
In this example, the TypeNameHandling
property is set to All
to include type information in the serialized JSON. The Converters
property is set to an instance of the ExceptionConverter
class, which is responsible for handling the serialization of exceptions with inner exceptions.
You can then register this custom serializer in your startup code like this:
builder.Services.AddSingleton();
This will ensure that the custom serializer is used for all Durable Functions in your application.
I hope this helps
I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.