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
Sam HobbsPosted Mar 23, 2011, 5:24 PM
VulpesPosted Mar 23, 2011, 6:51 AM
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 :)
PhilipPosted Mar 23, 2011, 6:34 AM
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?
VulpesPosted Mar 22, 2011, 11:57 AM
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());
PhilipPosted Mar 22, 2011, 8:13 AM
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!
FroglegPosted Mar 22, 2011, 8:11 AM