Need help,
I´m loading an xml file using
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
Everything works fine when I am debbuging.
However when I publish the application as a clickonce package something weird happens.
The above code works, however not the entire xml file gets loaded. The root node and first and second level nodes gets loaded but not the third and fourth level nodes (and so on..).
If I attach a debugger to the clickonce-application everything works fine again but as soon as I detach the debugger the xml document does not get "deep" loaded.
I have struggled with this for two days now.
Framework 3.5 (Winforms application)
Vista X64
VS2010
Thanks
Loading

FroglegRank #1,020 · 1.9K reputationPosted Mar 22, 2011, 4:11 AM EDT
Philip5 reputationPosted Mar 22, 2011, 4:13 AM EDT
Douple, triple checked it.
I tried to run the same application under Windows 7 (X64) and there it worked (same xml-file).
Vista bug?
Update:
Tested with Windows 7 in a virtual environment, same problem. Extremely annoying!
VulpesRank #55 · 29.2K reputationPosted Mar 22, 2011, 7:57 AM EDT
My only suggestion is to try using LINQ to XML instead of the legacy XmlDocument class:
using System.Xml.Linq;
// ...
XDocument xmlDoc = XDocument.Load(filePath);
MessageBox.Show(xmlDoc.ToString());
Philip5 reputationPosted Mar 23, 2011, 2:34 AM EDT
I was using a filesystemwatcher which triggered the system to read the file.
Apparently you can load the file into an XmlDocument (as well as a Linq XDocument) object without any error reported despite the fact that the file has not been fully written to disk.
During the debugging I had a breakpoint which halted the application so that the file could be fully written, so that must be why it always seemed to work during debugging.
Now to the next problem.
I am using something similar to this to find out when the file has been completely written. However throwing exceptions around does not seem like a good solution.
for (int i = 0; i < 100; i++)
{
FileStream fs = null;
try
{
fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 100);
fs.Close();
break;
}
catch
{
AppendDebugInfo("Waiting for file to become ready.");
Thread.Sleep(1000);
}
}
Any suggestions to how to know when a file has been completely written to disk?
VulpesRank #55 · 29.2K reputationPosted Mar 23, 2011, 2:51 AM EDT
Failing that, you could poll the file's GetLastWriteTime() method until it gives a changed value though I'm not sure it's really a better solution than what you're doing now :)
Sam HobbsRank #107 · 20.5K reputationPosted Mar 23, 2011, 1:24 PM EDT