473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Problem with XmlNode.ChildNodes across different machines

I'm having the darndest XML config file problem that I really need help with.

I'm supporting a .NET 1.1 desktop application with its own config file, and
I implement IConfigurationSectionHandler so I can have a custom config
section in my config file. The IConfigurationSectionHandler.Create method
just returns the 'section' XmlNode back to the consumer. The config file
looks kind of like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MyConfigSettings" type="MyAssembly.ConfigReader, MyAssembly" />
</configSections>
<appSettings>
</appSettings>
<MyConfigSettings>
<ConfigSet zone="Test">
<add key="FirstKey" value="FirstValue"/>
<add key="SecondKey" value="SecondValue"/>
<add key="ThirdKey" value="ThirdValue"/>
</ConfigSet>
<ConfigSet zone="Integration">
<add key="FirstKey" value="FirstValue"/>
<add key="SecondKey" value="SecondValue"/>
<add key="ThirdKey" value="ThirdValue"/>
</ConfigSet>
</MyConfigSettings>
</configuration>
Then I've got this section of code that looks like this:
Public Shared Sub SetConfigZone(ByVal Zone As String)

Dim debug As String

Try
debug &= "Checking Zone variable " & Environment.NewLine

If (Zone Is Nothing) Then
MessageBox.Show("Zone variable passed in is nothing")
End If

debug &= "Getting XmlNode from config file " & Environment.NewLine
Dim parent As XmlNode =
ConfigurationSettings.GetConfig("MyConfigSettings" )

debug &= "Checking parent variable " & Environment.NewLine
If (parent Is Nothing) Then
Throw New ConfigurationException("Unable to locate the
custom configuration section MyConfigSettings. Please check your config
file.")
End If

MessageBox.Show(parent.OuterXml)

debug &= "Beginning loop through nodes " & Environment.NewLine
For Each node As XmlNode In parent.ChildNodes
MessageBox.Show(node.OuterXml)
debug &= "Inspecting Node's zone attribute... " &
Environment.NewLine
If (node.Attributes("zone").Value = Zone) Then
debug &= "Correct node found... " & Environment.NewLine
debug &= "Creating new NameValueCollection... " &
Environment.NewLine
ConfigCommon.m_ConfigSettings = New NameValueCollection
debug &= "Looping through 'add' subnodes... " &
Environment.NewLine
For Each subNode As XmlNode In node.SelectNodes("add")
debug &= "Getting subnode's 'key' value... " &
Environment.NewLine

ConfigCommon.m_ConfigSettings.Add(subNode.Attribut es("key").Value,
subNode.Attributes("value").Value)
Next
Return
End If
Next
Catch ex As Exception
MessageBox.Show(debug, "Our debug message")
MessageBox.Show(ex.ToString(), "Our error message")
End Try

'If we get this far, we haven't found our configuration section
Throw New ConfigurationException("Unable to locate configuration
zone " & Zone)

End Sub

So here's my problem. This code has been working just great for the last
six to nine months, but all of a sudden about two weeks ago all of the new
machine builds our desktop group puts out fail at the following line:

If (node.Attributes("zone").Value = Zone) //fails on first
run through

On new machines, it's producing a NullReferenceException. But when I take
the exact same code and run it on anyone else's machine, it works just fine.
In fact, you'll notice that I added a lot of little debugs and
MessageBox.Show statements in there to try to pinpoint it. When I run the
code on my machine, I notice that the MessageBox.Show(node.OuterXml) produces
the first node. When I run this on a newly built machine, the
MessageBox.Show produces an empty string.

My question is: what is missing from these new builds that was in the old
builds? I think I've ruled out different versions of the .NET framework.
Even if this was a breaking change in .NET 2.0, I tried forcing the .NET
Framework in the config file to 1.1 and still got the same error. And the
users definitely have the .NET 1.1 Framework.

Please help.

Thanks.

Mar 14 '07 #1
5 2676
Hi,

In fact, I have run the application with your code and .config file on my
machine (with .net framework 2.0), but without any error. The code snippet
you posted in newsgroup is fine.
When I run the code on my machine, I notice that the
MessageBox.Show(node.OuterXml) >produces the first node. When I run this
on a newly built machine, the MessageBox.Show produces an empty string.

Is there any output by "MessageBox.Show(parent.OuterXml)" ?
I suggest you may output the parent.Attributes.count and through out each
Attribute of parent node rather than only output the attribute "zone".
There must be something wrong in Parent.Attributes.

Hope this helps,
Sincerely,
Wen Yuan

Mar 15 '07 #2
Hi Wen Yuan,
Is there any output by "MessageBox.Show(parent.OuterXml)" ?
On both the old and new builds, the parent.OuterXml displays just fine.

This app is written in .NET 1.1 and the users have the .NET 1.1 Framework on
their machines. Does this code run just fine for you in .NET 1.1?

Mar 15 '07 #3
Hello,
Thanks for your reply.

I uninstalled my .net framework 2.0 and installed .net framework 1.1 just
now. This is really a bug. I have reproduced this issue. The node.outXml
become null and I get the same exception as you.
But after I installed sp1 for .net frame work 1.1. The issue has gone away.
Apparently, this issue has been addressed in SP1 and .net framework 2.0.
(under my test).
For this reason, I suggest you may installed sp1 for .net 1.1 or installed
new .net 2.0 to resolved this issue.
You can download sp1 for .net 1.1 from the following website.
http://www.microsoft.com/downloads/d...&FamilyID=A8F5
654F-088E-40B2-BBDB-A83353618B38
[Microsoft .NET Framework 1.1 Service Pack 1]

Hope this will hope you. Also if you have any further issue, please feel
free to let me know. I'm glad to assist you.
Have a great weekend.
Sincerely,
Wen Yuan

Mar 16 '07 #4
Wen Yuan,

Thank you very much for your help. Independently yesterday I stumbled
across this article which outlines my issue:

http://support.microsoft.com/kb/823054

As you indicated, it is a bug having do with Config files represented as
XML. I am working with our Desktop team to determine which patch installed
in the last few months fixed it, as I don't believe we are running SP1 but
have applied numerous patches from 1.1. Converting to .NET 2.0 is not an
option for us, as it would require much more thorough testing of our
application.

Thanks again for your help.

Mar 16 '07 #5

Thanks for your feedback. You are welcome.:)
As you see, I think .NET 1.1 SP 1 will resolve the issue for you.

Have a great day,
Sincerely,
Wen Yuan

Mar 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ason | last post by:
Hi, I just tried to replace a single XmlNode with several ChildNodes. When doing this with the following code i found out that if you get the ChildNodes with 'ChildNodes' - property the nodes...
1
by: Venkat Venkataramanan | last post by:
Hello: Can somebody explain to me the usage of the XMLNode.ChildNodes? When there is a node that does not have any child node, the above method returns an array of 1. This member has the...
1
by: pmclinn | last post by:
Below I have copied in an xml page I'm trying to parse out and the code I'm currently using to do it. My code works great but I want to change the .Item(0). part of this code to a typed refrence...
1
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg.,...
0
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg.,...
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
2
by: Claudio | last post by:
Hi I'm trying to use XPath queries with streaming XML, but I cannot make it working. The solution I'm trying to implement is: create a XmlNode as soon as I have a full XML element and use the...
8
by: johnsonlau | last post by:
When I use document.write to replace the comment of a frame, I found that the page was always showing as loading in Firefox (2.0.0.2). But it seems that it is OK in IE6. Could someone help me...
2
by: banagani | last post by:
Hi, I am facing the issue on removing the element. Sample XML: <A name = “Blue”> <B> <C fileRef =” 0” idRef = “1”> </C>
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.