[release/10.0] [Blazor] OwningComponentBase Dispose method in .NET 10 gets back the original behavior
#64794
+121
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #64695 to release/10.0
/cc @javiercn @ilonatommy
Restore
Dispose(bool disposing)withdisposing=trueon async disposal for Blazor components.Description
In .NET 9, disposing a Blazor component would call
IDisposable.Dispose(), which then invokedDispose(bool disposing)withdisposing=true. This allowed user overrides ofDispose(bool disposing)to execute necessary cleanup logic for managed resources. However, in .NET 10, after introducingIAsyncDisposablesupport (PR #62583), the framework began invokingIAsyncDisposable.DisposeAsync(), which followed the typical .NET dispose pattern and calledDispose(false). This caused user code that depended ondisposing=trueto break, asDisposeAsync()was now incorrectly signaling a non-disposing context.This fix ensures backward compatibility by making
DisposeAsync()callDispose(true), just as in .NET 9 and earlier. Additionally, theIsDisposed = trueassignment has been removed fromDisposeAsyncCore(), and its handling is now consolidated withinDispose(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?
Regressed from: .NET 9
Risk
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
Packaging changes reviewed?