Skip to content

Report CA2007 for await foreach with WithCancellation - #57094

Draft
nagilson with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ca2007-await-foreach-cancellation
Draft

nagilson with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ca2007-await-foreach-cancellation

Conversation

Copilot AI commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

CA2007 skipped await foreach when WithCancellation(...) produced a ConfiguredCancelableAsyncEnumerable<T>, even though it preserves the captured context by default.

  • Analyzer

    • Recognizes BCL TaskAsyncEnumerableExtensions.WithCancellation.
    • Reports the collection expression while continuing to suppress explicitly configured chains.
  • Coverage

    • Covers diagnostics and fixes for:
      await foreach (var item in source.WithCancellation(token)) { }
    • Verifies no diagnostic for:
      await foreach (var item in source.WithCancellation(token).ConfigureAwait(false)) { }

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
3 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CA2007 not reporting await foreach with WithCancellation Report CA2007 for await foreach with WithCancellation Nov 13, 2026
Copilot AI requested a review from nagilson November 13, 2026 01:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CA2007 does not report await foreach over WithCancellation(...) without ConfigureAwait

2 participants