Warn on Blazor components with Dispose()/DisposeAsync() but no interface#67426
Open
dkamburov wants to merge 19 commits into
Open
Warn on Blazor components with Dispose()/DisposeAsync() but no interface#67426dkamburov wants to merge 19 commits into
dkamburov wants to merge 19 commits into
Conversation
Contributor
|
Thanks for your PR, @dkamburov. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Components analyzer that warns when a Blazor component declares Dispose() / DisposeAsync() but does not implement the corresponding disposal interface, helping prevent cleanup logic from silently never running.
Changes:
- Add
ComponentDisposableSanityAnalyzerto report new warnings BL0014 (Dispose()withoutIDisposable) and BL0015 (DisposeAsync()withoutIAsyncDisposable). - Add localized descriptor resources and wire them into
DiagnosticDescriptors. - Add unit tests covering the core warning/no-warning scenarios.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Components/Analyzers/src/ComponentDisposableSanityAnalyzer.cs | New analyzer that scans component types for Dispose/DisposeAsync methods and reports BL0014/BL0015. |
| src/Components/Analyzers/src/DiagnosticDescriptors.cs | Adds the two new DiagnosticDescriptors for BL0014/BL0015. |
| src/Components/Analyzers/src/Resources.resx | Adds titles/formats/descriptions for the two new diagnostics. |
| src/Components/Analyzers/test/ComponentDisposableSanityAnalyzerTest.cs | Adds tests validating BL0014/BL0015 reporting behavior. |
Youssef1313
reviewed
Jun 26, 2026
Youssef1313
reviewed
Jun 26, 2026
Youssef1313
reviewed
Jun 26, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Author
|
@dotnet-policy-service agree company="Infragistics, Inc" |
Open
3 tasks
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add analyzer for
Dispose()/DisposeAsync()interface sanity checksAdds two new analyzer diagnostics that catch a silent class of bugs where a Blazor component declares a dispose method but the runtime never calls it because the corresponding interface isn't implemented.
Description
Introduce
ComponentDisposableSanityAnalyzerto warn when Blazor components declareDispose()orDisposeAsync()without implementingIDisposableorIAsyncDisposable. Add diagnostics BL0015 and BL0016 with resource strings, and provide thorough analyzer tests for all relevant scenarios.Fixes #51714