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\" claus
Well, the problem is that some code somewhere isn't disposing of the FileStream
when it's done with it. When the FileStream
is finalized, it's trying to flush the data - at which point the exception is being thrown.
If that really is all of your code, it sounds like it's a bug in XmlDocument.Save()
, which should definitely close all its streams before returning. You could work around this by opening the FileStream
yourself (with a using
statement) and passing the stream to XmlDocument.Save
instead.