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!
Hi,
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
HTH,
Ann
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
privatefields and local variables of the followingIDisposabletypes, which are never disposed, closed, aliased, returned, or passed to other methods.
System.IOnamespace
System.IO.FileStreamSystem.IO.StreamReaderSystem.IO.StreamWriterSystem.Netnamespace
System.Net.WebClientSystem.Net.Socketsnamespace
System.Net.Sockets.SocketSystem.Net.Sockets.TcpClientSystem.Net.Sockets.UdpClientSystem.Drawingnamespace
System.Drawing.ImageSystem.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!
Hi,
Thanks for the pointer. Let’s wait for the language specialists to get here. I’m sure they’ll be interested in this.
Ann
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. 
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.
Thx,
Ann
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?
Thanks,
@Zargath
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,
@Caba_Sagi
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?
Thanks,
@Zargath
Thank you @Caba_Sagi!
