FileStream throws 'The OS handle's position is not what FileStream expected.' at Finalize() call

0

When i closing my application, FileStream sometimes throws IOException in the debug mode:

System.IO.IOException
  HResult=0x80131620
  Message=The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss.
  Source=mscorlib
  StackTrace:
   at System.IO.FileStream.VerifyOSHandlePosition()
   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()

I didn't check it in the release mode, because this error occurs very rarely. I use the FileStream like this:

using (var stream = new FileStream()) {
    // some code
}

No FileStream is open when i close the application.

My application using .NET Framework 4.5 and WPF

c#
wpf
io
filestream
asked on Stack Overflow Jun 11, 2019 by Wanderfort • edited Jun 11, 2019 by Wanderfort

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0