Skip to content

Breaking change docs: IHost.RunAsync/StopAsync throw when BackgroundService fails (.NET 11)#52863

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-backgroundservice-failure-handling
Open

Breaking change docs: IHost.RunAsync/StopAsync throw when BackgroundService fails (.NET 11)#52863
Copilot wants to merge 2 commits intomainfrom
copilot/fix-backgroundservice-failure-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

In .NET 11 Preview 3, when a BackgroundService.ExecuteAsync throws and BackgroundServiceExceptionBehavior is StopHost (default), the host-level async methods now propagate the exception instead of completing successfully—causing a non-zero exit code.

Changes

  • New article: docs/core/compatibility/extensions/11.0/ihost-runasync-stopasync-throw-backgroundservice-failure.md
    • Documents previous behavior (silent success), new behavior (exception propagation + AggregateException for multiple failures), reason (hiding failures was wrong), and migration path
  • 11.md: Added Extensions section (alphabetical order) referencing the new article
  • toc.yml: Added .NET 11 > Extensions entry

Recommended action from the article

Do nothing—non-zero exit on failure is correct. To preserve the old success-exit behavior:

try
{
    await host.RunAsync();
}
catch (Exception ex)
{
    // Log or inspect the exception if needed.
}

Affected APIs

HostingAbstractionsHostExtensions.RunAsync/Run/StopAsync/WaitForShutdownAsync/WaitForShutdown and the default IHost.StopAsync implementation.


Internal previews

📄 File 🔗 Preview link
docs/core/compatibility/11.md docs/core/compatibility/11
docs/core/compatibility/extensions/11.0/ihost-runasync-stopasync-throw-backgroundservice-failure.md docs/core/compatibility/extensions/11.0/ihost-runasync-stopasync-throw-backgroundservice-failure
docs/core/compatibility/toc.yml docs/core/compatibility/toc

…groundService fails in .NET 11

Agent-Logs-Url: https://github.com/dotnet/docs/sessions/ba90f62b-c56b-4f77-ac69-71212d4fe526

Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix background service exception handling in host methods Breaking change docs: IHost.RunAsync/StopAsync throw when BackgroundService fails (.NET 11) Apr 3, 2026
Copilot AI requested a review from gewarren April 3, 2026 21:49
@gewarren gewarren marked this pull request as ready for review April 4, 2026 01:49
@gewarren gewarren requested a review from a team as a code owner April 4, 2026 01:49
@gewarren gewarren requested review from Copilot and svick April 4, 2026 01:49
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

Adds a new .NET 11 breaking change article under the Extensions area describing exception propagation from host-level run/stop/wait APIs when a BackgroundService fails, and wires the article into the .NET 11 breaking-change index and TOC.

Changes:

  • Adds a new breaking change article documenting updated exception/exit-code behavior for IHost run/stop/wait APIs when BackgroundService.ExecuteAsync throws.
  • Adds an Extensions section to the .NET 11 breaking changes index page and links the new article.
  • Updates the compatibility TOC to include the new .NET 11 Extensions node and article link.

Reviewed changes

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

File Description
docs/core/compatibility/toc.yml Adds a .NET 11 Extensions TOC node pointing to the new breaking change article.
docs/core/compatibility/extensions/11.0/ihost-runasync-stopasync-throw-backgroundservice-failure.md New breaking change article documenting the behavior change, rationale, recommended action, and affected APIs.
docs/core/compatibility/11.md Adds an Extensions section and links the new breaking change article.

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.

[Breaking change]: IHost.RunAsync and IHost.StopAsync throw when a BackgroundService fails with an exception

3 participants