CA2000 and CA2202 Offer contradictory warnings - by Jonathan Allen

Status : 

  Postponed<br /><br />
		Due to current priorities, the product team decided to postpone the resolution of this item.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


12
0
Sign in
to vote
ID 535118 Comments
Status Closed Workarounds
Type Bug Repros 9
Opened 2/21/2010 12:41:13 AM
Access Restriction Public

Description

Correcting CA2000 will result in warning CA2202. Correcting CA2202 returns us back to CA2000.
Sign in to post a comment.
Posted by Microsoft on 8/5/2010 at 1:23 PM
We've added this issue to our feature backlog for consideration in a future release of Visual Studio.
Posted by Thomas_Eyde on 5/5/2010 at 11:11 AM
Can someone at Microsoft please provide a working piece of code, as I have yet to see something that actually works.

Take the following code in C#:

                using (var taxFile = File.Open(@"c:\thisfiledoesntExist.foo", FileMode.Open))
                {
                    var reader = new StreamReader(taxFile);
                    return int.Parse(reader.ReadLine() ?? "");
                }

the taxFile object should be disposed just fine. Who cares if the reader object tries to do the same when the garbage collector arrives to the party? Everything is out of scope, so nothing bad can happen.
Posted by Microsoft on 2/23/2010 at 11:35 AM
Hi,

Thank you for your feedback. In version 1 of your repro, CA2000 gives the warning because if StreamReader's constructor throws an exception, the newly created FileStream object is not disposed. In version 2, CA2202 gives the warning because new StreamReader object will assume ownership of the FileStream object and will dispose it. At the end of the using block around the FileStream object, it will dispose the FileStream object a second time. To fix this, you can change the outer using block, which is the one around the FileStream object, and have it dispose the FileStream object depending on whether the StreamReader object was created successfully.
We appreciate your valuable feedback and we will consider incorporating it in a future release of Visual Studio.

thanks,
Brahmnes
Posted by Microsoft on 2/23/2010 at 1:22 AM

Thanks for your feedback.

We are routing 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 Microsoft on 2/22/2010 at 7:04 PM
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)