Skip to content

[dotnet watch] Enable CA2007 (ConfigureAwait) for startup hook assembly#54116

Merged
jonathanpeppers merged 1 commit intorelease/10.0.4xxfrom
jonathanpeppers/enable-ca2007-dotnet-watch
Apr 30, 2026
Merged

[dotnet watch] Enable CA2007 (ConfigureAwait) for startup hook assembly#54116
jonathanpeppers merged 1 commit intorelease/10.0.4xxfrom
jonathanpeppers/enable-ca2007-dotnet-watch

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented Apr 27, 2026

Enable CA2007 as an error in the HotReloadAgent.Host .editorconfig and add ConfigureAwait(false) to awaits in the startup hook assembly. This assembly runs inside the user's app process where a SynchronizationContext may be present (e.g. UIKitSynchronizationContext on iOS), so missing ConfigureAwait(false) can cause deadlocks.

Context: #54023 (comment)

@jonathanpeppers jonathanpeppers changed the base branch from main to release/10.0.4xx April 29, 2026 19:30
Enable CA2007 as an error in the HotReloadAgent.Host .editorconfig and
add ConfigureAwait(false) to awaits in the startup hook assembly. This
assembly runs inside the user's app process where a
SynchronizationContext may be present (e.g. UIKitSynchronizationContext
on iOS), so missing ConfigureAwait(false) can cause deadlocks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/enable-ca2007-dotnet-watch branch from db753fa to 5b79f2d Compare April 29, 2026 19:37
@jonathanpeppers jonathanpeppers changed the title [dotnet watch] Enable CA2007 (ConfigureAwait) analyzer [dotnet watch] Enable CA2007 (ConfigureAwait) for startup hook assembly Apr 29, 2026
@jonathanpeppers jonathanpeppers marked this pull request as ready for review April 29, 2026 22:06
Copilot AI review requested due to automatic review settings April 29, 2026 22:06
@jonathanpeppers jonathanpeppers requested review from a team and tmat as code owners April 29, 2026 22:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables CA2007 as an error for the HotReloadAgent.Host startup hook assembly and updates awaits to use ConfigureAwait(false) to avoid deadlocks when a SynchronizationContext is present in the user’s app process (e.g., iOS UIKitSynchronizationContext).

Changes:

  • Enable CA2007 as an error in HotReloadAgent.Host/.editorconfig.
  • Add .ConfigureAwait(false) to awaited calls in the startup hook notification path.
  • Add .ConfigureAwait(false) to NamedPipeTransport.SendAsync awaits.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Dotnet.Watch/HotReloadAgent.Host/StartupHook.cs Adds ConfigureAwait(false) when sending the rude-edit notification to avoid context-related deadlocks.
src/Dotnet.Watch/HotReloadAgent.Host/NamedPipeTransport.cs Adds ConfigureAwait(false) to pipe write awaits to comply with CA2007 and avoid context capture.
src/Dotnet.Watch/HotReloadAgent.Host/.editorconfig Enables CA2007 as an error for this assembly to prevent future context-capturing awaits.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants