question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a code analyzer to ensure that razor pages that define Dispose actually implement IDisposable

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Mar 10, 2022

@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.

0reactions
msftbot[bot]commented, Mar 11, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found