Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New method overloads added to System.Linq.Queryable #23421

Closed
eiriktsarpalis opened this issue Mar 22, 2021 · 1 comment · Fixed by #23557
Closed

New method overloads added to System.Linq.Queryable #23421

eiriktsarpalis opened this issue Mar 22, 2021 · 1 comment · Fixed by #23557
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3

Comments

@eiriktsarpalis
Copy link
Member

eiriktsarpalis commented Mar 22, 2021

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
@PRMerger7 PRMerger7 added the Pri3 label Mar 22, 2021
@dotnet-bot dotnet-bot added ⌚ Not Triaged Not triaged breaking-change Indicates a .NET Core breaking change doc-idea Indicates issues that are suggestions for new topics [org][type][category] labels Mar 22, 2021
@gewarren gewarren self-assigned this Mar 22, 2021
@gewarren gewarren added 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release Pri1 High priority, do before Pri2 and Pri3 and removed ⌚ Not Triaged Not triaged Pri3 labels Mar 22, 2021
@Scooletz
Copy link

It's really nice to see an issue being raised for it and calling out other providers to share their opinion about it. Really well done 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants