[release/9.0-staging] Handle .NET 10 MemoryExtensions.Contains overload with comparer #37183
+315
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #37176 for EF 9.0 (see #37182 for 8.0 fix)
Description
C# 14 first-class spans causes MemoryExtensions.Contains instead of Enumerable.Contains to be resolved, forcing LINQ providers to identify the former in additional to the latter. In addition, .NET 10 introduced a 3-parameter overload to MemoryExtensions.Contains which accepts a comparer, that gets resolved in some situations. While we already backported support for MemoryExtensions.Contains to EF Core 8 and 9, to allow these versions to work with C# 14, we didn't backport a separate change to also support the new .NET 10 overload.
Customer impact
Customers upgrading to .NET 10 but staying on EF 8 or 9 start experiencing failures in some LINQ queries that use Contains. The common case is Contains over an enum array:
Customers upgrading to EF 10 are not affected.
How found
Multiple customers reported on 9.0
Regression
Partial: occurs only when upgrading to .NET 10 but keeping older EF 8 or 9.
Testing
Tested manually, as we don't have automated testing for .NET 10 on older EF versions.
Risk
Very low, targeted change that's very low-risk, and already well-tested in EF 10. Quirk added.