Skip to content

LINQ Contains breaking change in .NET 10 #123533

Description

@Youssef1313

Description

Run the following snippet on .NET 9 and .NET 10.

using System.Collections.ObjectModel;

var first = new MyEquatableClass?[] { null, null, null };
var second = new ReadOnlyCollection<MyEquatableClass?>(new MyEquatableClass[] { new MyEquatableClass() });

Console.WriteLine(first.Concat(second).Contains(new MyEquatableClass()));


class MyEquatableClass : IEquatable<MyEquatableClass>
{
    public bool Equals(MyEquatableClass? other)
        => other is not null;
}

Reproduction Steps

Run above snippet.

.NET 9 prints true.
.NET 10 prints false.

Expected behavior

Either a clear breaking change notice (if it's there somewhere, sorry I missed it!), or maintaining the compatibility.

Actual behavior

A behavioral breaking change that I cannot find a documentation for in https://learn.microsoft.com/en-us/dotnet/core/compatibility/10#core-net-libraries.

Regression?

Yes, likely from #112684

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions