In this post let's see how we can preserve Stack<T> order when it's getting passed between Orchestrators/Activities in a .NET Isolated Azure Durable Function.
In Durable Functions in the .NET isolated worker, the Serialization default behavior has changed from Newtonsoft.Json to System.Text.Json.
I have already written a post about preserving Stack Order in an In-Process Azure Durable Functionshere. I am using the same code example, instead converted it to isolated worker. So I am not going to write down the entire example code to describe the issue here, you can have a look at the previous post.
You can see in the below screenshot, the order of Stack<T> is not preserved with default Serializer options.
|
using DurableFunctions.Isolated.StackSerialization.Converters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Text.Json;
IHost host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.Configure<JsonSerializerOptions>(options =>
{ // Add custom converter to serialize and deserialize a Stack<T>
options.Converters.Add(new JsonConverterFactoryForStackOfT());
});
})
.Build();
host.Run();
Correct Result |
DurableFunctions.Isolated.StackSerialization
Hope this helps.
Happy Coding.
No comments:
Post a Comment