Looking for the equivalent of CA2000 in SonarQube

Hi! I’m trying to find the equivalent of CA2000 in SonarQube, but haven’t had any luck. Any ideas how this can be achived? Thanks!


I assume we’re talking about C#? We have a number of rules around the proper use of iDisposable. I suppose this one is the most directly relevant:

“IDisposables” should be disposed


Hi Ann,

Thanks for your reply! Yes, I’m talking about C#.

I was looking at that rule and it would work, however, it only tracks specific types.

This rule tracks private fields and local variables of the following IDisposable types, which are never disposed, closed, aliased, returned, or passed to other methods.

  • System.IO namespace
    • System.IO.FileStream
    • System.IO.StreamReader
    • System.IO.StreamWriter
  • System.Net namespace
    • System.Net.WebClient
  • System.Net.Sockets namespace
    • System.Net.Sockets.Socket
    • System.Net.Sockets.TcpClient
    • System.Net.Sockets.UdpClient
  • System.Drawing namespace
    • System.Drawing.Image
    • System.Drawing.Bitmap

I have a situation where an IDisposable type that is not in that list was not disposed and was causing a memory leak.



Thanks for the pointer. Let’s wait for the language specialists to get here. I’m sure they’ll be interested in this.


1 Like

Hey @Caba_Sagi,

I was wondering if you could take a quick look at my question.


Hi @Zargath,

I understand your impatience, but please don’t invoke people who aren’t already participating in a thread.

The language developers make a point of monitoring the community, but they do so… in their own time. :joy:

And for transparency, we just finished the big annual company event & everyone’s been focused on preparing for & participating in that for a while now.


Hi @Zargath

We do not have a rule with an exact match for CA2000. However, there is rule S2931 which covers the case of having IDisposable members inside a class, and there is the rule suggested by @ganncamp which as you already saw covers only part of the CA2000 functionality.

Hi @Caba_Sagi,

Thanks for getting back to me and sorry for pulling you into the thread like I did.

We have both of the rules mentioned activated and neither of them flagged the issue. I think it’s because the variable is scoped to the function and is not a class property or variable. Could this be a blind spot with the current rules?


Hi @Zargath

Yes, it indeed is. We are very thankful to you for helping us find this blind spot.
Together with other team members we will revisit all our IDisposable related rules and we will try to find a way to cover this blind spot (Maybe we will change one of the existing rules or we will add a new one, we have not yet decided).

Best regards,

Hi @Caba_Sagi,

I’m happy I can help. Is there a way for me to follow the development of this issue? Is that kind of information public?


Hi @Zargath

I created an issue for this, so you can follow the development.

All the best,

Thank you @Caba_Sagi!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.