Link to home
Start Free TrialLog in
Avatar of JedNebula
JedNebulaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Reading from an XML file

I have a problem which is a bit difficult to explain. I have written a VB.NET (2005) Windows Forms project which gets loaded on start-up from the registry Run key on the client machines. The project gets it's program settings from an local XML file, but gets a different value (-1) when run from the registry to when it's run from the start menu start-up folder, or just manually loaded (4).

As it's a bit difficult to test, I've recreated the problem on a smaller exe, which can be downloaded here:
http://www.bigbucketofdata.co.uk/tmp/XMLLoadTest.zip

You should find that if you add the exe in the bin directory to the registry you will get a message box of -1, but 4 otherwise. I'm really perplexed now....

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Velio
Velio
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You XML has a value of 4 in it..
<?xml version="1.0" standalone="yes"?>
<OptionsDB>
  <OptionsTBL>
    <SourceServerID>4</SourceServerID>
    <DestServerID>4</DestServerID>
  </OptionsTBL>
</OptionsDB>

Open in new window

When I changed it to this I got -1 as a popup:
<?xml version="1.0" standalone="yes"?>
<OptionsDB>
  <OptionsTBL>
    <SourceServerID>-1</SourceServerID>
    <DestServerID>-1</DestServerID>
  </OptionsTBL>
</OptionsDB>

Open in new window

Avatar of JedNebula

ASKER

Yes after I posted the question, I found out that specifying the whole path for the XML file seems to work. How come the DataSet.ReadXML doesn't throw an exception though? Surely it can either read the file and get all the data, or it can't...

Zach, I'm not really sure what you mean. You will get the value you put in there come back when you double-click the exe normally. You only get the wrong value when it is run from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run in the registry (and you've not put -1 in the XML file as a value)

I chose ASP.Net as it's the next nearest zone I could find where people would be most familiar with XML.
glad you sorted it out :)

i also found it quite weird. not very familiar with the inner workings of the ReadXML method, so i can't comment as to why it doesn't throw an exception. the documentation only mentions a security exception.
That is odd.. I wonder why it doesn't throw an exception?
Ah well. At least I know what I've got to do..   :-)

Thanks guys.