Reputation: 31
I use System.Xml.XmlDocument to load a file,then wait a minute throw the timeout error. Curiously, the code can work in another project.
XmlDocument.LoadXml() is throw the error too.
System.Xml.XmlDocument doc = new XmlDocument();
doc.Load(@"D:\work\xxx.svg");
add:
I see the stacktrace info, it's WebException, error code System.Net.HttpWebRequest.GetResponse().
So the XmlDocument.Load() method is think of my filepath as url, but i don't understand why it work in another project is all right
Upvotes: 1
Views: 637
Reputation: 31
I follow the stacktrace, saw the problem:
[XmlException: Open external DTD "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd": An error occurred while the operation timed out. ]
Then I add XMLreaderSetting:
XmlDocument xmlDoc = new XmlDocument();
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
XmlReader reader = XmlReader.Create(@"D:\\111.txt", settings);
xmlDoc.Load(reader);
They final work.
But I am curious why in another project is no problem.
I hope this answer can help another with the same difficulties.
Upvotes: 2