I recently downloaded Visual Studio 2013 and I ran the Code Analysis on a project I'm working on. Its thrown up a couple of issues that I'm working through but one in particular is about how I am using the "using" IDisposable statement.
Here's an example of my code:
using (MemoryStream msDecrypt = new MemoryStream(encryptedText.ToBase64Byte()))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
return srDecrypt.ReadToEnd();
}
}
}
I understand the Analysis warning is trying to tell me that disposing of multiple objects in this way could throw an object disposed issue.
I'm sure that disposing on one object is not going to throw an exception in the case above. So should I modify my code or keep as is?