Skip to content

Commit

Permalink
Don't use WeakReferences in the round trip test, as the target may ge…
Browse files Browse the repository at this point in the history
…t freed in the meantime, fixes #104905 (#106967)
  • Loading branch information
adamsitnik authored and github-actions committed Sep 17, 2024
1 parent 5f4f896 commit 57c2918
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public class BasicObjectTests : Common.BasicObjectTests<FormattedObjectSerialize
[MemberData(nameof(SerializableObjects))]
public void BasicObjectsRoundTripAndMatch(object value, TypeSerializableValue[] _)
{
if (value is WeakReference || (value.GetType().IsGenericType && value.GetType().GetGenericTypeDefinition() == typeof(WeakReference<>)))
{
// 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();
Expand Down

0 comments on commit 57c2918

Please sign in to comment.