Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Dec 16, 2025

Backport of #64695 to release/10.0

/cc @javiercn @ilonatommy

Restore Dispose(bool disposing) with disposing=true on async disposal for Blazor components.

Description

In .NET 9, disposing a Blazor component would call IDisposable.Dispose(), which then invoked Dispose(bool disposing) with disposing=true. This allowed user overrides of Dispose(bool disposing) to execute necessary cleanup logic for managed resources. However, in .NET 10, after introducing IAsyncDisposable support (PR #62583), the framework began invoking IAsyncDisposable.DisposeAsync(), which followed the typical .NET dispose pattern and called Dispose(false). This caused user code that depended on disposing=true to break, as DisposeAsync() was now incorrectly signaling a non-disposing context.

This fix ensures backward compatibility by making DisposeAsync() call Dispose(true), just as in .NET 9 and earlier. Additionally, the IsDisposed = true assignment has been removed from DisposeAsyncCore(), and its handling is now consolidated within Dispose(bool disposing) for consistency and to prevent double-disposal.

Fixes #64669

Customer Impact

Without this fix, users overriding Dispose(bool disposing) in Blazor components could see their cleanup logic silently skipped in .NET 10, leading to resource leaks or unexpected behavior. This change restores the expected contract and makes async disposal consistent and safe for component authors who rely on the documented pattern.

Regression?

  • Yes
  • No

Regressed from: .NET 9

Risk

  • High
  • Medium
  • Low

This change restores prior contract and behavior; automated tests confirm idempotency and compatibility. Since the implementation centralizes disposal logic, risk of introducing regressions is low.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@github-actions github-actions bot requested a review from a team as a code owner December 16, 2025 12:42
@javiercn javiercn added this to the 10.0.x milestone Dec 16, 2025
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Dec 17, 2025
@ilonatommy ilonatommy self-assigned this Dec 17, 2025
@ilonatommy ilonatommy requested a review from javiercn December 17, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants