Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2004

Tip: Looking for answers? Try searching our database.

Parsing of App.config varies by machine

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Neils Christoffersen - 13 Oct 2004 17:09 GMT
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.
Neils Christoffersen - 15 Oct 2004 17:33 GMT
This issue was resolved by applying .NET Framework 1.1 Service Pack 1 to the
machine.

> I've run into a strage and frustrating problem. I've written some
> configuration classes that implement IConfigurationSectionHandler to read
[quoted text clipped - 59 lines]
>
> Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.