I have this in my app.config
file:
<Configuration>
<configsections>
<section name="FeaturesSection" type="SampleCatalog.FeaturesSection" />
</configsections>
<FeaturesSection>
<Feature Name="CCH" US="true" EM="false" Sequence="1" />
<Feature Name="PLT" US="true" EM="false" Sequence="1" />
<Feature Name="PD" US="true" EM="false" Sequence="1" />
</FeaturesSection>
<Configuration>
My code in the class goes as below:
public class FeaturesSection:ConfigurationSection
{
public FeatureCollection Features
{
get{return (FeatureCollection)base["Features"};
}
}
public class FeatureCollection:ConfigurationElementCollection
{
public Feature this[int index]{
get{ return (Feature)BaseGet(index);}
set{
if(BaseGet(index)!= null)
BaseRemoveAt(index);
BaseAdd(index,value);
}
}
protected override ConfigurationElement CreateNewElement()
{
return new Feature();
}
protected override object GetElementKey(ConfigurationElement element){
return ((Feature)element);
}
}
public class Feature: ConfigurationElement
{
[ConfigurationProperty("Name",IsRequired=true)]
public string Name {get; set;}
[ConfigurationProperty("US",IsRequired=true)]
public bool US {get; set;}
[ConfigurationProperty("EM",IsRequired=true)]
public bool EM {get; set;}
[ConfigurationProperty("Sequence",IsRequired=true)]
public string Sequence {get; set;}
}
Now when I run this code:
var mysection = (FeaturesSection)ConfigurationManager.GetSection("FeaturesSection");
I'm getting exceptions.
An error occurred creating the configuration section handler for FeaturesSection: Could not load type 'SampleCatalog.FeaturesSection' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (C:\Users\Venkata_Poruri_Pavan\Documents\Visual Studio 2013\Projects\SampleCatalog\SampleCatalog\bin\Debug\SampleCatalog.vshost.exe.Config line 4)
Please help, kindly accept my apologies as I couldn't paste the code here.
Thanks