title: IOException in StreamWriter
body: <p>I am using StreamWriter serialization to overwrite to an existing xml file.  Below is my code segment:</p>
  
  <pre><code>using(StreamWriter sw = new StreamWriter("\\hard disk\logs\test.xml"))
  {
     this.Serializer.Serialize(sw,this.StateObject);
  }
  </code></pre>
  
  <p>For some reason from time to time I keep getting IOException on the StreamWriter line, it is very general and it does not have inner exception when i tried to debug it.  </p>
  
  <p>StreamWriter line actually clear out the content of my test.xml file and make it to become 0 byte but yet it throws exception at the same time.  Because of this exception the serialization never took place so I ended up with a 0 byte file.  I can use the exception handler to correct this 0 byte but I am more interested in fixing the original issue of why StreamWriter throws exception in the first place.</p>
  
  <p>Have you guys ever seen this behavior before from StreamWriter? I ensure you that the path is valid, and that I verified it has permission and no other process are accessing that file (even if there is I would have seen that error in my stack trace)</p>
  
  <p>I wonder the fact that I'm running on Window CE has anything to do with it? even though MSDN indicates Window CE supports this System.IO library</p>
  
  <p>Edit:</p>
  
  <p>Below is my stacktrace, the <code>CopyData()</code> function is the one that contains my serialization.  Looking at the value at the line <code>System.IO.__Error.WinIOError(Int32 errorCode, String str)</code>, I see my str value is "\hard disk\logs\test.xml" and the errorCode is <strong>2147483648</strong>.</p>
  
  <pre><code>at System.IO.__Error.WinIOError(Int32 errorCode, String str)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
  at System.IO.StreamWriter.CreateFile(String path, Boolean append)
  at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
  at System.IO.StreamWriter..ctor(String path)
  at Shs.ScanPanel.CA.DataManager.DataManagercr.CopyData(Object data)
  at System.Threading.Timer.ring()
  </code></pre>