Unable to read in my custom .config section
Posted
by Pure.Krome
on Stack Overflow
See other posts from Stack Overflow
or by Pure.Krome
Published on 2010-02-24T08:10:56Z
Indexed on
2010/05/20
19:20 UTC
Read the original article
Hit count: 470
Hi folks,
NOTE: this is very very similar to this SO question, but I need some more help.
i'm trying to make the following section in my .config file, but i get an exception when trying to access this section.
.config file
<configSections>
<section name="foos" type="Ackbar.Mvc.Models.Foo.FooCollection, Ackbar.Mvc" requirePermission="false"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" requirePermission="false" />
</configSections>
<foos>
<add name="aaa" something="zzz"/>
<add name="bbb" something="yyy"/>
<add name="ccc" something="xxx"/>
</foos>
Ok, so this means i need to make two classes
classes
public class FooCollection : ConfigurationElementCollection
{
... with my custom overrides, etc. ...
}
and
public class FooElement : ConfigurationElement
{
[ConfigurationProperty("Name", IsRequired = true)]
public string Name { .. }
[ConfigurationProperty("Something ", IsRequired = true)]
public string Something { .. }
[ConfigurationProperty("IsDefault ", IsRequired = false, DefaultValue = false)]
public bool IsDefault { .. }
}
Kewl. Now, when i do the following ....
var whatever = ConfigurationManager.GetSection("foos")
is throws the following exception :-
An error occurred creating the configuration section handler for foos: Type 'Ackbar.Mvc.Models.Foos.FooCollection' does not inherit from 'System.Configuration.IConfigurationSectionHandler'.
Can someone please help me? I don't want to wrap the collection INSIDE a parent section.
Cheers :)
© Stack Overflow or respective owner