I develop a simple app, when i try to save an XMLDocument to a thumb drive which doesn't have enough free space, weird thing happens. Though i already added "try catch" clause for XMLDocument.Save(filePath), i still get an unhandled exception, and the exception seems to be thrown from GC finalization thread (seems GC tries to flush another 4096 bytes which the disk does not have). I think it is a common scenario to use XMLDocument object , i wonder what is wrong?
code snippet:
XmlDocument query = new XmlDocument();
query.Load("g:\\test.xml");
... //modify the content of query to make it bigger
try
{
query.Save("g:\\test.xml");
}
catch(Exception ex)
{}
Exception stacktrace as below:
mscorlib.dll!System.IO.__Error.WinIOError(int errorCode = 112, string maybeFullPath = "") + 0x498 bytes mscorlib.dll!System.IO.FileStream.WriteCore(byte[] buffer, int offset, int count) + 0x119 bytes mscorlib.dll!System.IO.FileStream.FlushWrite(bool calledFromFinalizer) + 0x22 bytes mscorlib.dll!System.IO.FileStream.Dispose(bool disposing = false) + 0x57 bytes
mscorlib.dll!System.IO.FileStream.Finalize() + 0x1b bytes