Intermittently, I see an IO exception at XMLDocument.Save(). Initially, I thought it's the same as question in the following links: 1. XmlDocument.Save unhandled exception thrown from GC thread 2. Memory exception while XDocument.Save()
But, My call stack is different from the ones discussed in above threads. Here is my call stack: ------- Base Exception (start here) --------- Root cause may be due to this exception: 'System.IO.IOException' Message=IOException,
StackTrace= at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(Char[] buffer)
at System.IO.TextWriter.WriteLine()
at System.Xml.XmlTextWriter.Indent(Boolean beforeEndElement)
at System.Xml.XmlTextWriter.AutoComplete(Token token)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)
at System.Xml.XmlDOMTextWriter.WriteStartElement(String prefix, String localName, String ns)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw)
at System.Xml.XmlDocument.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.Save(String filename)
Problem is my IOException doesn't quote any reason. Following is the code:
XmlDocument traceXml = new XmlDocument();
traceXml.Load(traceFilename);
XmlElement root = t30Trace.DocumentElement;
XmlAttribute jobId = t30Trace.CreateAttribute("JobId");
jobId.Value = "45";
root.Attributes.Append(jobId);
traceXml.Save(traceFilename);
Wanted to understand more on this. Any help will be appreciated.