1

I have an application which will copy 1000 files from One folder to another. After each file is copied we will write the Copy Success/Failure information into a separate file.

At some time, during writing this copy information in a file, StreamWriter.WriteLine throws the following exception:

10/28/2014 12.21.02.068 Message : Not enough storage is available to process this command. Filename : Copying file C:\Program Files\XYZ\SampleFile.xml to C:\Program Files\ABC\SampleFile.xml.xml | Inner Exception : | Type : System.IO.IOException | Source : mscorlib

Not enough storage is available to process this command.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__ConsoleStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
   at System.IO.TextWriter.WriteLine(String value)
   at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
   at System.Console.WriteLine(String value)
   at VersionActivator.VersionActivationController.LogMessage(String message)                            
mscorlib : Not enough storage is available to process this command.**

But this application works fine when the PC initialized in safe mode.

My Code :

foreach (FileInfo fi in source.GetFiles())
{
    if (fi.Exists)
    {
        string destFileName = Path.Combine(target.FullName, fi.Name);

        // If the file is readonly, make it non-readonly
        if (File.Exists(destFileName))
        {
             File.SetAttributes(destFileName, FileAttributes.Normal); // IMS 2793051209
        }
        LogMessage(string.Format("Copying file {0} to {1}", fi.FullName, destFileName));
        fi.CopyTo(destFileName, true);
    }
}

public void LogMessage(string message)
{
    try
    {
        **Console.WriteLine(message); // This is the place am getting IO exception**
        if (m_LogWriter != null)
        {
            m_LogWriter.WriteLine(
              string.Format(@"{0} {1}"
              , DateTime.Now.ToString("MM/dd/yyyy HH.mm.ss.fff")
              , message)
            );
        }
    }
    catch (Exception ex)
    {
        WriteException(ex, message);
              throw;
    }
}
Siva Gopal
  • 3,474
  • 1
  • 25
  • 22
Sugumar
  • 223
  • 1
  • 3
  • 13
  • Did you redirect your `Console`? – angelsl Nov 27 '14 at 08:04
  • This link may have some useful info for your case: http://stackoverflow.com/questions/25665321/out-of-memory-exception-when-using-file-stream-write-byte-to-output-progress-thr – Siva Gopal Nov 27 '14 at 08:12
  • 1
    do you see any entries in the Eventlog of Windows that are connected to your exception? – Jehof Nov 27 '14 at 09:16
  • Where is the log file being written? Are you sure there is actually enough disk space there? Are you sure the account used to run the program has enough quota there? (I think you'd have to write a lot more than 1000 lines of text to hit the OOM issue described in the link in the other comment). – Peter Duniho Nov 27 '14 at 09:16
  • yes, it is having 20 GB of free space. logs are being written in C drive. There is no entries in Eventlog. – Sugumar Nov 28 '14 at 08:57

0 Answers0