Code inspection: The 'EnumeratorCancellation' attribute is only effective on a parameter of type 'CancellationToken' in an async-iterator method returning 'IAsyncEnumerable<>'.
This inspection reports [EnumeratorCancellation] used where it has no effect. The attribute is only meaningful on a CancellationToken parameter of an async iterator method that returns IAsyncEnumerable<T>. On other parameter types or other method shapes, it does nothing.
Example
using System.Collections.Generic;
using System.Runtime.CompilerServices;
class C
{
public async IAsyncEnumerable<int> M([EnumeratorCancellation] int token)
{
yield return token;
}
}
using System.Collections.Generic;
class C
{
public async IAsyncEnumerable<int> M(int token)
{
yield return token;
}
}
Quick-fix
The quick-fix removes the ineffective attribute. Another valid manual fix is to change the method so the attribute is applied to a CancellationToken parameter of an async iterator returning IAsyncEnumerable<T>.
21 April 2026