From f8fcf2bf751388620d743331b96a4bd52936c644 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 29 Aug 2024 16:55:54 +0200 Subject: [PATCH] Don't use WeakReferences in the round trip test, as the target may get freed in the meantime, fixes #104905 (#106967) --- .../BinaryFormatTests/FormattedObject/BasicObjectTests.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs index b316a3e32b502..fd5fdc9b8c01a 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs @@ -14,6 +14,14 @@ public class BasicObjectTests : Common.BasicObjectTests))) + { + // We can root the provided value, but we can't root the deserialized value: + // GC can free the target of WeakReference after it gets deserialized, + // but before it gets returned from BinaryFormatter.Deserialize. + return; + } + // We need to round trip through the BinaryFormatter as a few objects in tests remove // serialized data on deserialization. BinaryFormatter formatter = new();