Code inspection: Async-iterator has one or more parameters of type 'CancellationToken' but none of them is annotated with the 'EnumeratorCancellation' attribute.
This inspection reports an async iterator method that has a CancellationToken parameter but does not mark any such parameter with [EnumeratorCancellation]. Without that attribute, the cancellation token passed by await foreach through GetAsyncEnumerator(...) is not forwarded to the iterator parameter you probably intended to use.
Example
using System.Collections.Generic;
using System.Threading;
class C
{
public async IAsyncEnumerable<int> M(CancellationToken token)
{
yield return 0;
}
}
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
class C
{
public async IAsyncEnumerable<int> M([EnumeratorCancellation] CancellationToken token)
{
yield return 0;
}
}
Quick-fix
The quick-fix adds the [EnumeratorCancellation] attribute to the chosen CancellationToken parameter.
21 April 2026