From 1911bad2b0f64b17a1a29af9027c782d9fbbb22e Mon Sep 17 00:00:00 2001 From: Kevin McLoughlin <19433524+WilliamHBonney@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:14:25 +0000 Subject: [PATCH 1/3] Make FailureDetails.Properties optional for DataContractSerializer FailureDetails is [Serializable] without ISerializable, so DataContractSerializer treats every field as required. Data persisted before the Properties property was added (e.g. Netherite commit logs and history) fails to deserialize with 'Expecting element _x003C_Properties_x003E_k__BackingField'. Mark the backing field [OptionalField] so older payloads deserialize with Properties = null. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4bf274ab-99ca-4766-831e-75f351459122 --- .../FailureDetailsSerializationTests.cs | 88 +++++++++++++++++++ src/DurableTask.Core/FailureDetails.cs | 4 + 2 files changed, 92 insertions(+) create mode 100644 Test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs diff --git a/Test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs b/Test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs new file mode 100644 index 000000000..d8ec6b798 --- /dev/null +++ b/Test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs @@ -0,0 +1,88 @@ +// --------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// --------------------------------------------------------------- +#nullable enable + +namespace DurableTask.Core.Tests +{ + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Runtime.Serialization; + using System.Xml; + using System.Xml.Linq; + using DurableTask.Core.History; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class FailureDetailsSerializationTests + { + [TestMethod] + public void DataContractSerializer_TaskFailedEventWithoutPropertiesField_Deserializes() + { + // Simulates history persisted by DurableTask.Core versions that predate FailureDetails.Properties. + var innerFailure = new FailureDetails("System.TimeoutException", "inner", "inner stack", innerFailure: null, isNonRetriable: false); + var failureDetails = new FailureDetails("System.InvalidOperationException", "outer", "outer stack", innerFailure, isNonRetriable: true); + var original = new TaskFailedEvent(eventId: 5, taskScheduledId: 3, "reason", "details", failureDetails); + + string legacyXml = RemovePropertiesElements(Serialize(original)); + Assert.IsFalse(legacyXml.Contains("Properties"), "The legacy payload should not contain the Properties field."); + + TaskFailedEvent result = Deserialize(legacyXml); + + Assert.AreEqual(3, result.TaskScheduledId); + Assert.IsNotNull(result.FailureDetails); + Assert.AreEqual("System.InvalidOperationException", result.FailureDetails.ErrorType); + Assert.AreEqual("outer", result.FailureDetails.ErrorMessage); + Assert.AreEqual("outer stack", result.FailureDetails.StackTrace); + Assert.IsTrue(result.FailureDetails.IsNonRetriable); + Assert.IsNull(result.FailureDetails.Properties); + Assert.IsNotNull(result.FailureDetails.InnerFailure); + Assert.AreEqual(innerFailure.ErrorType, result.FailureDetails.InnerFailure.ErrorType); + Assert.AreEqual(innerFailure.ErrorMessage, result.FailureDetails.InnerFailure.ErrorMessage); + Assert.IsNull(result.FailureDetails.InnerFailure.Properties); + } + + [TestMethod] + public void DataContractSerializer_FailureDetailsWithProperties_RoundTrips() + { + var properties = new Dictionary { ["Code"] = "E42", ["Missing"] = null }; + var original = new FailureDetails("System.Exception", "message", "stack", innerFailure: null, isNonRetriable: false, properties); + + FailureDetails result = Deserialize(Serialize(original)); + + Assert.IsNotNull(result.Properties); + Assert.AreEqual("E42", result.Properties["Code"]); + Assert.IsTrue(result.Properties.ContainsKey("Missing")); + Assert.IsNull(result.Properties["Missing"]); + } + + static string Serialize(T value) + { + var serializer = new DataContractSerializer(typeof(T)); + using var stream = new MemoryStream(); + serializer.WriteObject(stream, value); + stream.Position = 0; + using var reader = new StreamReader(stream); + return reader.ReadToEnd(); + } + + static T Deserialize(string xml) + { + var serializer = new DataContractSerializer(typeof(T)); + using var stringReader = new StringReader(xml); + using var xmlReader = XmlReader.Create(stringReader); + return (T)serializer.ReadObject(xmlReader)!; + } + + static string RemovePropertiesElements(string xml) + { + XDocument document = XDocument.Parse(xml); + document.Descendants() + .Where(e => e.Name.LocalName.Contains("Properties")) + .ToList() + .ForEach(e => e.Remove()); + return document.ToString(SaveOptions.DisableFormatting); + } + } +} diff --git a/src/DurableTask.Core/FailureDetails.cs b/src/DurableTask.Core/FailureDetails.cs index c4ad18895..400767ff5 100644 --- a/src/DurableTask.Core/FailureDetails.cs +++ b/src/DurableTask.Core/FailureDetails.cs @@ -162,6 +162,10 @@ protected FailureDetails(SerializationInfo info, StreamingContext context) /// /// Gets additional properties associated with the failure. /// + /// + /// The backing field is optional so that data persisted before this property existed can still be deserialized. + /// + [field: OptionalField] public IDictionary? Properties { get; } /// From cbe14cbd9982a0152aad031ce167d7d53e0cbae9 Mon Sep 17 00:00:00 2001 From: Kevin McLoughlin <19433524+WilliamHBonney@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:22:37 +0000 Subject: [PATCH 2/3] Move FailureDetailsSerializationTests to lowercase test/ directory Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4bf274ab-99ca-4766-831e-75f351459122 --- .../DurableTask.Core.Tests/FailureDetailsSerializationTests.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Test => test}/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs (100%) diff --git a/Test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs b/test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs similarity index 100% rename from Test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs rename to test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs From 955bc56d507e13185354ecaed78f3e61df46f74f Mon Sep 17 00:00:00 2001 From: Kevin McLoughlin <19433524+WilliamHBonney@users.noreply.github.com> Date: Thu, 12 Nov 2026 08:46:51 +0000 Subject: [PATCH 3/3] Match serialization test license header to repository convention Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: de587369-3d13-49fa-8654-999bf350e3c4 --- .../FailureDetailsSerializationTests.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs b/test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs index d8ec6b798..cb85f0e6f 100644 --- a/test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs +++ b/test/DurableTask.Core.Tests/FailureDetailsSerializationTests.cs @@ -1,6 +1,15 @@ -// --------------------------------------------------------------- -// Copyright (c) Microsoft Corporation. All rights reserved. -// --------------------------------------------------------------- +// ---------------------------------------------------------------------------------- +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- #nullable enable namespace DurableTask.Core.Tests