Closing a open file after running out of space on a disk.

I am running into a problem while trying to handle an out of space on the disk exception. Whenever I get an exception that there is "Not enough space on the disk" (really is a System.IO.Exception with the message just given), I try to close the file, delete it, and then continue my error handling. I am using the System.IO.FileStream class to do the writing. The problem is that when I try to close the file, I get another "Not enough space on the disk" System.IO.Exception. I believe it is because the class is trying to flush the stream before closing. I have tried closing the underlying stream, but get the same exception. I have also tried setting the stream length to zero, but get the same result. This leaves me unable to remove the file I was writing. Anyone have any ideas on how to resolve this problem?

Thank you,
Craig

[839 byte] By [minton] at [2007-12-16]
# 1
Update:

This is on Visual Studio 2003 Version 7.1.3008 and Microsoft .NET Framework 1.1.4322 SP2.

After some more research it appears that every method I use attempts to flush writes before doing the operation, including setting the length to zero. Also, the underlying Stream appears to just virtualize all of the methods that looked like a possible work-around.

minton at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Figured I'd update anyone interested on the answer to this. It is a bug and has been corrected for future versions. The entire post can be found here.

Resolved as Fixed by Microsoft on 2005-08-01 at 15:26:14

This issue has been fixed and the handle will now be closed. This is fixed in V2.0 and also the next service pack of V1.1. There will still be an exception in this case, but the handle will be closed so that the file can be deleted.

Anthony Moore
Development Lead
Base Class Libraries.

minton at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified