Skip to content

Enable CA2007 (ConfigureAwait) analyzer for src/ libraries#367

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/enable-configureawait-analyzer
Open

Enable CA2007 (ConfigureAwait) analyzer for src/ libraries#367
Copilot wants to merge 3 commits into
mainfrom
copilot/enable-configureawait-analyzer

Conversation

Copilot AI commented May 20, 2026

Copy link
Copy Markdown
Contributor

Enforces ConfigureAwait(false) on awaited tasks in library code via the CA2007 analyzer, mirroring dotnet/sdk#54116. Missing ConfigureAwait(false) can deadlock these netstandard2.0 libraries when consumed by hosts with a SynchronizationContext (MSBuild, IDEs).

Changes

  • .editorconfigdotnet_diagnostic.CA2007.severity = error scoped to [src/**.cs]. Tests are intentionally exempt.
  • src/Directory.Build.props (new) — sets EnableNETAnalyzers=true and AnalysisLevel=latest so the SDK's CA analyzers also run against netstandard2.0 (they only auto-enable for net5.0+, but netstandard2.0 is precisely where the rule matters most).
  • .github/copilot-instructions.md — documents the convention.

Notes

  • No production source changes were needed; the existing codebase already calls ConfigureAwait(false) on every await under src/.
  • Verified the rule fires on both netstandard2.0 and net10.0 by temporarily dropping a .ConfigureAwait(false) call and confirming error CA2007 from each target.

Copilot AI linked an issue May 20, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Enable ConfigureAwait(false) analyzer for consistency Enable CA2007 (ConfigureAwait) analyzer for src/ libraries May 20, 2026
Copilot AI requested a review from rmarinho May 20, 2026 13:22
@rmarinho rmarinho marked this pull request as ready for review June 8, 2026 18:44
@rmarinho rmarinho requested a review from jonathanpeppers as a code owner June 8, 2026 18:44
Copilot AI review requested due to automatic review settings June 8, 2026 18:44
@rmarinho rmarinho requested a review from simonrozsival as a code owner June 8, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables the SDK’s built-in CA analyzers for src/ library projects (including netstandard2.0) and enforces CA2007 as an error to require ConfigureAwait(false) usage in library code, reducing deadlock risk when consumed under a SynchronizationContext (MSBuild/IDEs).

Changes:

  • Enforce CA2007 as an error for src/**.cs via .editorconfig (tests excluded).
  • Add src/Directory.Build.props to turn on SDK analyzers (EnableNETAnalyzers=true, AnalysisLevel=latest) for src/ projects.
  • Document the ConfigureAwait(false) convention in .github/copilot-instructions.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Directory.Build.props Enables SDK analyzers for src/ projects (including netstandard2.0).
.github/copilot-instructions.md Documents the required ConfigureAwait(false) convention for src/.
.editorconfig Sets CA2007 to error for src/ C# source files.

- **No whitespace-only diffs**: before committing, run `git diff --stat` and verify only files with intentional code changes appear. If a file shows as fully rewritten (all lines removed and re-added) you have introduced line-ending or trailing-whitespace changes — revert that file with `git checkout -- <file>` and re-apply only your code change. Never commit whitespace-only or line-ending-only changes.
- **File-scoped namespaces**: all new files should use file-scoped namespaces (`namespace Foo;` instead of `namespace Foo { ... }`).
- **Static `HttpClient`**: `HttpClient` instances must be `static` to avoid socket exhaustion. See [HttpClient guidelines](https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use). Do not create per-instance `HttpClient` fields or dispose them in `IDisposable`.
- **`ConfigureAwait(false)`**: every `await` in `src/` must end with `.ConfigureAwait (false)` — these libraries run inside hosts (MSBuild, IDEs) that have a `SynchronizationContext`, and resuming on it can cause deadlocks on `netstandard2.0`. This is enforced as `error CA2007` for source code (see `.editorconfig`); tests are exempt.
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.

Enable ConfigureAwait(false) analyzer

3 participants