Code
public static void StrToFile(string value, string cFileName)
{
if (File.Exists(cFileName) == true)
{
File.Delete(cFileName);
}
FileStream oFs = new FileStream(cFileName, FileMode.CreateNew, FileAccess.ReadWrite);
StreamWriter oWriter = new StreamWriter(oFs);
oWriter.Write(value);
oWriter.Flush();
oWriter.Close();
oFs.Close();
}
causes in Visual Studio Community Edition code Analyze error at line oFs.Close();
Warning CA2202 Object 'oFs' can be disposed more than once in method 'Core.StrToFile(string, string)'. To avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an object.
How to fix this ?