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

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 779134 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 2/13/2013 7:00:37 AM
Access Restriction Public


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.
Sign in to post a comment.
Posted by Deon [MSFT] on 4/29/2014 at 12:30 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Patrick [MSFT] on 5/30/2013 at 11:03 AM
Hi Rob,
I have updated the documentation to include your scenario.
Posted by Macy [MSFT] 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 Macy [MSFT] 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 Macy [MSFT] 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.