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 dotnet#104905 (dotnet#106967)
  • Loading branch information
adamsitnik authored and jtschuster committed Sep 17, 2024
1 parent e5a8609 commit f8fcf2b
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 f8fcf2b

Please sign in to comment.