I'm trying to to store grouped configuration settings in my app.config, but I'm having difficulty in drilling down to the lowest level. My config file looks like this:

XML Code:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.     <configSections>
  4.         <sectionGroup name="deploymentEnvironments">
  5.             <section name="Dev" type="System.Configuration.NameValueSectionHandler" />
  6.             <section name="SIT" type="System.Configuration.NameValueSectionHandler" />
  7.             <section name="UAT" type="System.Configuration.NameValueSectionHandler" />
  8.             <section name="Live" type="System.Configuration.NameValueSectionHandler" />
  9.         </sectionGroup>
  10.     </configSections>
  11.     <deploymentEnvironments>
  12.         <Dev>
  13.             <Database>DevDatabaseName</Database>
  14.             <Server>DevDatabaseServer</Server>
  15.             <LogLocation>DevLogLocation</LogLocation>
  16.         </Dev>
  17.         <SIT>
  18.             <Database>SITDatabaseName</Database>
  19.             <Server>SITDatabaseServer</Server>
  20.             <LogLocation>SITLogLocation</LogLocation>
  21.         </SIT>
  22.         <UAT>
  23.             <Database>UATDatabaseName</Database>
  24.             <Server>UATDatabaseServer</Server>
  25.             <LogLocation>UATLogLocation</LogLocation>
  26.         </UAT>
  27.         <Live>
  28.             <Database>LiveDatabaseName</Database>
  29.             <Server>LiveDatabaseServer</Server>
  30.             <LogLocation>LiveLogLocation</LogLocation>
  31.         </Live>
  32.     </deploymentEnvironments>
  33.     <appSettings>
  34.         <add key="Environment" value="Dev"/>
  35.     </appSettings>
  36.     <startup>
  37.         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  38.     </startup>
  39. </configuration>

In VB, I read it like this:

VB.Net Code:
  1. Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
  2.         Dim sectionGroups As ConfigurationSectionGroupCollection = config.SectionGroups
  3.         Dim sectionGroup As ConfigurationSectionGroup = sectionGroups("deploymentEnvironments")
  4.  
  5.         '# This correctly gets the "Dev" group
  6.         Dim configurationSection As ConfigurationSection = sectionGroup.Sections(ConfigurationManager.AppSettings("Environment"))
  7.  
  8.         Dim section As NameValueCollection
  9.  
  10.         '# configurationSection.SectionInformation.Name returns the name "Dev". This line gives "section" a value of Nothing.
  11.         section = CType(ConfigurationManager.GetSection(configurationSection.SectionInformation.Name), NameValueCollection)
  12.  
  13.         '# configurationSection.SectionInformation.SectionName returns the name "deploymentEnvironments/Dev". This throws an
  14.         '# error of "Unrecognized element."""
  15.         section = CType(ConfigurationManager.GetSection(configurationSection.SectionInformation.SectionName), NameValueCollection)

Any idea how I can get to the elements (Database, Server etc) within the Dev section?