XmlDocument.Save unhandled exception thrown from GC thread

后端 未结 1 1459
礼貌的吻别
礼貌的吻别 2021-01-21 03:47

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

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 04:00

    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.

    0 讨论(0)
提交回复
热议问题