Add a code analyzer to ensure that razor pages that define Dispose actually implement IDisposable
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
It’s very easy when writing a Razor page to forget to add the @implements IDisposable
line at the top when implementing the Dispose pattern. This can mean that developers can unwittingly have dangling handlers which will cause memory leaks because the Dispose
method they carefully wrote will never actually get called.
Describe the solution you’d like
It would be great to have a code analyzer in VS that will put a wiggly red line under Dispose methods that are declared in a .razor file that doesn’t explicitly have the statement @implements IDisposable
.
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
CA1063: Implement IDisposable correctly (code analysis)
Every unsealed type that declares and implements the IDisposable interface must provide its own protected virtual void Dispose(bool) method.
Read more >Four ways to dispose IDisposables in ASP.NET Core
This post presents the options for disposing services in ASP.NET Core: manually; using the DI container; with RegisterForDispose; ...
Read more >Implement a Dispose method
In this article, learn to implement the Dispose method, which releases unmanaged resources used by your code in .NET.
Read more >Display error message when using IDisposable interface ...
The error message is correct: you did not implement IDisposable . You need an explicit interface implementation void IDisposable.Dispose() ...
Read more >Why is there need for an explicit Dispose() method in asp. ...
1 Answer. Dispose is for releasing "unmanaged" resources (for example, sockets, file handles, Bitmap handles, etc), and if it's being called ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Webreaper thanks for contacting us.
The compiler should take care of that by producing a compile time error if you don’t have a Dispose method within your implementation.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.