From bd2608d1df05f41ba18bd6d996fb407ce2d78a14 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Mon, 26 Aug 2024 15:53:42 +0200 Subject: [PATCH] Don't use WeakReferences in the round trip test, as the target may get freed in the meantime, fixes #104905 --- .../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();