Hello CandidKilsborne,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Problem
I understand that you are developing an Azure Durable Functions project in .NET 8 Isolated mode and you're facing an issue where an object (mergedPayload
) loses its values (all fields become null) when passed between function calls within the orchestrator. You would also like to know how to correctly pass and retain the modifications of the object between the function calls in a Durable Function.
Solution
The behavior you've described in your explanation can occur due to serialization and deserialization issues in Durable Functions. Regarding your question, this is how to pass an object between functions and keep the modifications within a Durable Function in a .NET 8 Isolated project.
- Ensure your data class is serializable by using appropriate attributes for JSON serialization.
using System.Text.Json.Serialization; public class Payload { [JsonPropertyName("property1")] public string Property1 { get; set; } [JsonPropertyName("property2")] public int Property2 { get; set; } // Add other properties as needed }
- Define the orchestrator function that calls activity functions and passes the modified object between them.
public static class DurableFunctionOrchestrator { [Function("OrchestratorFunction")] public static async Task RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context) { var initialPayload = new Payload { Property1 = "InitialValue", Property2 = 100 }; var mergedPayload = await context.CallActivityAsync<Payload>("MergeFunction", initialPayload); var resultPayload = await context.CallActivityAsync<Payload>("ProcessFunction", mergedPayload); // Log or use the final result as needed context.SetOutput(resultPayload); } }
- Ensure you log the payload before and after each modification to trace the state of your object.
using Microsoft.Extensions.Logging; using System.Text.Json; public static class ActivityFunctions { [Function("MergeFunction")] public static async Task<Payload> MergeFunction([ActivityTrigger] Payload payload, ILogger log) { log.LogInformation($"MergeFunction received payload: {JsonSerializer.Serialize(payload)}"); // Modify the payload payload.Property1 = "MergedValue"; log.LogInformation($"MergeFunction modified payload: {JsonSerializer.Serialize(payload)}"); return payload; } [Function("ProcessFunction")] public static async Task<Payload> ProcessFunction([ActivityTrigger] Payload payload, ILogger log) { log.LogInformation($"ProcessFunction received payload: {JsonSerializer.Serialize(payload)}"); // Further modify the payload payload.Property2 += 200; log.LogInformation($"ProcessFunction modified payload: {JsonSerializer.Serialize(payload)}"); return payload; } }
By following the simple three steps above, the object retains its modifications as it is passed between the functions in your Durable Function orchestration.
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam