Hi my config file look like this
="1.0"="utf-8"
<configuration>
<configSections>
<sectionGroup name="connections" type="System.Configuration.ConfigurationSectionGroup, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" >
<section name="test2" type="ELT.credentials, ELT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<section name="test1" type="ELT.credentials, ELT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</sectionGroup>
</configSections>
<connections>
<test2 connectionName="test2" dbUserID="test2"/>
<test1 connectionName="test1" dbUserID="test1"/>
</connections>
</configuration>
and i am trying to access the elements of section like this
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;
and my credential file is
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; }
}
}
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.