8000 System.Linq.Async is being assimilated into .NET 10 but System.Linq.AsyncEnumerable doesn't seem to be on parity and breaks pre-.NET 10 code. · Issue #49162 · dotnet/sdk · GitHub
[go: up one dir, main page]

Skip to content
8000

System.Linq.Async is being assimilated into .NET 10 but System.Linq.AsyncEnumerable doesn't seem to be on parity and breaks pre-.NET 10 code. #49162

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

Closed
Xen0byte opened this issue May 27, 2025 · 3 comments

Comments

@Xen0byte
Copy link

Describe the bug

It seems like async lambdas are no longer supported in System.Linq.AsyncEnumerable in .NET 10 but at the same time the compiler will raise an ambiguous reference error if System.Linq.Async is installed.

To Reproduce

previously, with System.Linq.Async, something along the lines of the following was possible

int number = await new List<int>() { 1, 2, 3 }.ToAsyncEnumerable()
    .SingleAwaitAsync(async (value) => { await Task.Delay(500); return value.Equals(2); });

however, with System.Linq.AsyncEnumerable, the equivalent doesn't compile

int number = await new List<int>() { 1, 2, 3 }.ToAsyncEnumerable()
    .SingleAsync(async (value) => { await Task.Delay(500); return value.Equals(2); });

Exceptions (if any)

Cannot convert async lambda expression to delegate type 'Func<int, bool>'.
An async lambda expression may return void, Task or Task<T>, none of which are convertible to 'Func<int, bool>'.

Further technical details

  • Visual Studio Enterprise 2022 (64-bit) 17.14.2 Preview 1.0
  • .NET 10.0.100-preview.4.25258.110
@dotnet-policy-service dotnet-policy-service bot added the untriaged Request triage from a team member label May 27, 2025
@reflectronic
Copy link
reflectronic commented May 31, 2025

You need to add a CancellationToken parameter to your lambda

Func<TSource,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<bool>> predicate

https://learn.microsoft.com/en-us/dotnet/api/system.linq.asyncenumerable.singleasync?view=net-10.0#system-linq-asyncenumerable-singleasync-1(system-collections-generic-iasyncenumerable((-0))-system-func((-0-system-threading-cancellationtoken-system-threading-tasks-valuetask((system-boolean))))-system-threading-cancellationtoken)

@Xen0byte
Copy link
Author

I see! Many thanks @reflectronic, I'll give it a try as soon as I get the chance and then update this issue accordingly.

@Xen0byte
Copy link
Author

Indeed, the following works just fine:

int number = await new List<int>() { 1, 2, 3 }.ToAsyncEnumerable()
    .SingleAsync(async (value, cancellationToken) => { await Task.Delay(500); return value.Equals(2); });

And then the cancellation token can be propagated to inner tasks, if needed:

... await Task.Delay(500, cancellationToken); ...

I should have inspected the overloads better.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged Request triage from a team member label May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0