ca2202

CA2202 Warning from Code Analysis for OracleConnection disposal

We are getting the following warning from Code Analysis in Visual Studio 2010 and I'm wondering if this is a false positive that we can safely ignore or the code should be refactored to correctly dispose the object. The relevant code: public void MyFunction() { OracleConnection oraConnection = null; OracleCommand oraCommand = n...

C# CA2000:Dispose objects before losing scope using FileStream/XmlTextReader

I have lots of code like this: FileStream fs = File.Open(@"C:\Temp\SNB-RSS.xml", FileMode.Open); using (XmlTextReader reader = new XmlTextReader(fs)) { /* Some other code */ } This gives me the following Code Analysis warning: CA2000 : Microsoft.Reliability : In method 'SF_Tester.Run()', object 'fs' is not disposed along all ex...

How to dispose of an object that is iterated through via its Next property?

I have an object that uses some underlying native resources, and has a pointer to the next instance, which I iterate through similar to: MyObject begin = null; try { begin = GetFirst(); while (begin != null) { MyObject next = begin.Next(); // do something with begin begin.Dispose(); begin = ...