Home Dashboard Directory Help
Search

[CodeAnalysis] Documentation for CA2000 warning must list additional cases where suppressing the warning is allowed by RobSiklos


Status: 

Closed
 as Fixed Help for as Fixed


3
0
Sign in
to vote
Type: Bug
ID: 779134
Opened: 2/13/2013 7:00:37 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

The documentation for the Code Analysis warning CA2000:Dispose objects before losing scope says the following:

"Do not suppress a warning from this rule unless you have called a method on your object that calls Dispose, such as Close".

However, there is another valid case for suppressing the warning.

The documentation should be enhanced to say that suppressing the warning is also valid if the method returns an IDisposable object which wraps the undisposed object.
Details
Sign in to post a comment.
Posted by Microsoft on 5/30/2013 at 11:03 AM
Hi Rob,
I have updated the documentation to include your scenario.
Thanks,
Patrick
Posted by Microsoft on 2/14/2013 at 11:45 PM
Thanks for your update. We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by RobSiklos on 2/14/2013 at 6:31 AM
Ok - I attached a VS2012 project showing the behaviour. Just compile the project and you will get the CA2000 warning.

Because the GenerateFoo() method returns an IDisposable object which wraps the "bar" instance which the warning is complaining about, we either should not get the warning, or the docs should be updated to list this as a valid case for suppression.
Posted by Microsoft on 2/13/2013 at 9:31 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

Please submit this information to us within 4 business days. We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 2/13/2013 at 7:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Andrey Belykh on 2/13/2013 at 7:02 AM
... or enhance the CA to actually detect this case and not issue a warning.
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
Connect779134.zip 2/14/2013 9 KB