-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
New method overloads added to System.Linq.Queryable
We have added new public method overloads to System.Linq.Queryable as part of the new features implemented in dotnet/runtime#47231. This is known to break query provider implementations whose reflection code isn't sufficiently robust when looking up methods (cf. dotnet/efcore#24002, dotnet/runtime#49683).
Version introduced
6.0
Old behavior
The following code snippet executes successfully:
typeof(System.Linq.Queryable)
.GetMethods(BindingFlags.Public | BindingFlags.Static)
.Where(m => m.Name == "ElementAt")
.Single();
New behavior
The above code snippet now throws the exception:
System.InvalidOperationException: Sequence contains more than one element
at System.Linq.ThrowHelper.ThrowMoreThanOneElementException() in C:\Users\eitsarpa\devel\dotnet\runtime\src\libraries\System.Linq\src\System\Linq\ThrowHelper.cs:line 18
at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found) in C:\Users\eitsarpa\devel\dotnet\runtime\src\libraries\System.Linq\src\System\Linq\Single.cs:line 89
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) in C:\Users\eitsarpa\devel\dotnet\runtime\src\libraries\System.Linq\src\System\Linq\Single.cs:line 13
Reason for change
Extending the LINQ queryable API with new overloads.
Recommended action
Query provider library authors are advised to ensure that their reflection code is tolerant of method overload additions, e.g. by using a Type.GetMethod()
overload that explicitly accepts the method's parameter types.
Category
LINQ
Affected APIs
New overloads have been added for the following queryable extension methods:
ElementAt
/Take
Min
/Max
FirstOrDefault
/LastOrDefault
/SingleOrDefault
.Zip
Issue metadata
- Issue type: breaking-change