Note that there are some explanatory texts on larger screens.

plurals
  1. POTextWriter.WriteLine IO Exception - The specified network name is no longer available
    primarykey
    data
    text
    <p>I am trying to write text file after reading from a large tab delimited text file in a console application. Issue is that if I run many instances of this exe concurrently on a server, it gives me runtime error at TextWriter.WriteLine and then application crashes because of unhandled exception. This happens with all the instances. I fail to understand the reason for this behavior.. Is it because I am not using StringBuilder which will use memory dynamically ?</p> <p>My code is as follows :</p> <pre><code> StreamReader sr = new StreamReader(@FilePath, System.Text.Encoding.Default); string mainLine = sr.ReadLine(); string[] fileHeaders = mainLine.Split(new string[] { "\t" }, StringSplitOptions.None); string newLine = ""; System.IO.StreamWriter outFileSw = new System.IO.StreamWriter(@outFile); while (!sr.EndOfStream) { mainLine = sr.ReadLine(); string[] originalLine = mainLine.Split(new string[] { "\t" }, StringSplitOptions.None); newLine = ""; for (int i = 0; i &lt; fileHeaders.Length; i++) { if(fileHeaders[i].Trim() != "") newLine = newLine + fileHeaders[i].Trim() + "=" + originalLine[i].Trim() + "&amp;"; } outFileSw.WriteLine(newLine.Remove(newLine.Length - 1)); FileInfo fileInfo = new FileInfo(@outFile); if (fileInfo.Length &gt; (1.3 * 1024.0 * 1024.0 * 1024.0)) // greater than 1.3 GB { outFileSw.Close(); outFileNumber = outFileNumber + 1; outFileSw = new System.IO.StreamWriter(@outFile + outFileNumber.ToString() + ".txt"); } } outFileSw.Dispose(); sr.Close(); sr.Dispose(); </code></pre> <p>Error details are :</p> <pre><code>Exception Message: The specified network name is no longer available. Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count) at System.IO.FileStream.Write(Byte[] array, 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 ExampleExe.ExampleProcess.FnFiles() Unhandled Exception: System.IO.IOException: The specified network name is no longer available. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count) at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer) at System.IO.FileStream.Dispose(Boolean disposing) at System.IO.FileStream.Finalize() </code></pre> <p>Thanks, Kanu</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload