Reading config file section values when section group is present
<p>My config file looks like this:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;configuration&gt;
        &lt;configSections&gt;
            &lt;sectionGroup name="connections" type="System.Configuration.ConfigurationSectionGroup, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" &gt;
                &lt;section name="test2" type="ELT.credentials, ELT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
                &lt;section name="test1" type="ELT.credentials, ELT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
            &lt;/sectionGroup&gt;
        &lt;/configSections&gt;

        &lt;connections&gt;
            &lt;test2 connectionName="test2" dbUserID="test2"/&gt;
            &lt;test1 connectionName="test1" dbUserID="test1"/&gt;
        &lt;/connections&gt;
    &lt;/configuration&gt;
</code></pre>

<p>and I am trying to access the elements of section like this: </p>

<pre><code>ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"abcd.exe.config";
Configuration config1 = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
string str = cmbConnections.SelectedItem.ToString();
credentials credential1 = new credentials();
credential1 = config1.GetSection(str) as credentials;
txtDatabaseUserId.Text = credential1.DBUserID;
</code></pre>

<p>and my credential file is </p>

<pre><code>class credentials : ConfigurationSection
    {
        public credentials()
        {
        }
        [ConfigurationProperty("connectionName")]
        public string ConnectionName
        {
            get { return (string)this["connectionName"]; }
            set { this["connectionName"] = value; }
        }
        [ConfigurationProperty("dbUserID")]
        public string DBUserID
        {
            get { return (string)this["dbUserID"]; }
            set { this["dbUserID"] = value; }
        }
     }
</code></pre>

<p>When I run this code it is giving me an error "object reference not set to an instance of variable". How can I get the values for dbuserID for all the sections?</p>
