Parsing of App.config varies by machine

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've run into a strage and frustrating problem. I've written some
configuration classes that implement IConfigurationSectionHandler to read
custom sections in my App.config file.

On my primary development machine they work great. This morning I started
debugging the application on a different machine and I'm getting
ConfigurationExceptions in my classes. The problem seems to be that the
App.config is being read differently; it tries to parse whitespace that it
didn't on the first machine.

Here is my Create() method:

public object Create ( object parent, object configContext,
System.Xml.XmlNode section)
{
Hashtable servers = new Hashtable();

foreach (XmlNode srvNode in section.ChildNodes)
{
NameValueSectionHandler h = new NameValueSectionHandler();
NameValueCollection nvc;

nvc = (NameValueCollection) h.Create(parent, configContext, srvNode);
// this is where exceptions are being thrown

int id = Convert.ToInt32(nvc["ID"]);

servers.Add(id, new Server( nvc["Node"], nvc["User"], nvc["Password"],
id));
}
return servers;
}

Here is the relevant section of App.config:
<Servers>
<srv1>
<add key="ID" value="1" />
<add key="Node" value="node1" />
<add key="User" value="XXXXXX" />
<add key="Password" value="XXXXXX" />
</srv1>

<srv2>
<add key="ID" value="2" />
<add key="Node" value="node2" />
<add key="User" value="XXXXXX" />
<add key="Password" value="XXXXXX" />
</srv2>
</Servers>

I've done some experimenting and found that on the second machine (where the
code is failng) the foreach loop is executed five times. On iterations 1, 3
and 5, srvNode contains just whitespace (InnerXml == "" and InnerText
consists of \r\n's and \t's) and on iterations 2 and 4 srvNode contains the
proper child nodes (<srv1> and <srv2>, respectively) as expected.

On the machine I originally wrote the code on, the loop is executed only
twice, once for each child node of <Servers>.

Does anyone have an explanation for this? I haven't changed any
machine-level configurations that I'm aware of.

Thanks.
 
Back
Top