Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,
I have work with some XML operation. I have developed a Console application, I didn't face any issues in xml loading part running with visual studio.

but when I run the EXE file with command prompt, I have faced XML loading issue.
What is the solution here?

What I have tried:

C#
public XmlDocument xmlDoc = new XmlDocument();
string xml="E:\before.xml";
xmlDoc.LoadXml(xml);
Posted
Updated 17-Jun-19 1:04am
Comments
Nirav Prabtani 17-Jun-19 4:34am    
What is an error ?
Member 10242311 17-Jun-19 4:44am    
C:\Users\201875>E:\Files\AutoUpdater.exe E:\Updater\00560-ch0003_Release_141_Jan2019.docx E:\Updater\00560-ch0003_before.xml
Invalid XML document. The document does not have a root element.


In this second line is the error. this is happened only running with executable files in command prompt.
Richard MacCutchan 17-Jun-19 5:37am    
Please show the content of your XML file. And what is the Word document being passed in for?
Patrice T 17-Jun-19 4:35am    
"I have faced XML loading issue."
Our issue is that your didn't told us what is your issue.
Member 10242311 17-Jun-19 4:55am    
C:\Users\201875>E:\Files\AutoUpdater.exe E:\Updater\00560-ch0003_Release_141_Jan2019.docx E:\Updater\00560-ch0003_before.xml
Invalid XML document. The document does not have a root element.


In this second line is the error. this is happened only running with executable files in command prompt.

If it works in dev but fails in production, then the most likely reason is simply that your data is different, and the file(s) you are reading in production are not valid XML files.

Start by logging the file paths your code uses in production when it fails (a try...catch block helps with this) and include the actual data in the log if it's not too big. That way, you can do a post crash analysis to find out what exactly your user is trying to work with, and use that in dev to reproduce the problem and fix it.
But without that? You are just guessing what the problem might be and cannot solve it!
 
Share this answer
 
Comments
Member 10242311 17-Jun-19 7:07am    
Hi OriginalGriff, I have used valid XML file only. in both dev & production, I used the same file.

but this is working fine in dev, but throws exception in production (executed file).
OriginalGriff 17-Jun-19 7:15am    
And how have you assured that?
Did you add logging and look at exactly what you are reading from where?
As suggested most likely just different data. For example trying to load the word document as XML. And as suggested you can output the exact path etc to try to find out what is going on.

As an alternative, if you can reproduce the error on your development system try adding the following method call at the start of your program then compile it and run from the command line again:
Debugger.Launch Method (System.Diagnostics) | Microsoft Docs[^]

When it is running you will see what looks like an error message. But it isn't - it is a message that allows you to debug the application, without having to start it from Visual Studio.

This method does not work if it is only reproducible on a system without development tools. In that case better log output is the way to go.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900