A memory exception while XDocument.Save ()

I am trying to save XDcoument to a flash drive that does not have enough memory. (This is a special test condition for the application) Although the application provides an exception, as shown below, I cannot get this in the try catch block around XDocument.Save (filePath). This looks like a delayed throw. Is this a LINQ problem or am I doing something wrong?

alt text http://img211.imageshack.us/img211/8324/exce.png

 System.IO.IOException was unhandled
 Message="There is not enough space on the disk.\r\n"
 Source="mscorlib"
 StackTrace:
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   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()
+3
source share
4 answers

. XDocument.Save(string) "using", , . , , System.Xml.XmlUtf8RawTextReader .

: Microsoft, , Dispose(). Close().

, connect.microsoft.com. , , . , . , , , .

, XDocument.Save(TextWriter), StreamWriter, XML.

+5

. Finalize, Dispose, FlushWrite, WriteCore, .

, .

, , , .

+1

,

 using (XmlWriter writer = XmlWriter.Create(fileName, xmlWriterSettings))
 {
     this.Save(writer);
 }

, .
, Save.

: Dispose d , XDocument, Save?

0

XDocument.Save(string) , Dispose. using: - ( )

via (XmlWriter writer = XmlWriter.Create(fileName, xmlWriterSettings)) this.Save(writer);

And XmlWriter has Dispose(), it implements the interface IDisposable.

0
source

Source: https://habr.com/ru/post/1728357/


All Articles