Custom Configuration Section - .NET 2.0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to create a custom configuration section that looks like so:

<global>
<environment name="x">
<appSettings>
<add key="foo" value="bar" />
</appSettings>
</environment>
<environment name="y">
<appSettings>
<add key="foo" value="bar" />
</appSettings>
</environment>
</global>

My custom ConfigurationSection class has the following property:

[ConfigurationProperty("environments", IsDefaultCollection = true)]
public EnvironmentConfigElementCollection Environments
{
get { return (EnvironmentConfigElementCollection)base["environments"]; }
}

I keep getting an error, "unrecognized element 'environment', line 2". Does
anyone have any ideas? At my wits ends here. It's my understanding from
examples in docs that "IsDefaultCollection" property tells .NET not to expect
a wrapper tag, so would think it would view the "environment" tag as a member
of the collection, but it doesn't appear to be working.

Thanks,
William
 
As a follow-up to my post, I got the following to work:

<global>
<environments>
<add name="dev">
<appSettings>
<add key="SmtpServer" value="global.smtp.com - dev env value" />
<add key="AdServer" value="global.ad.com - dev env value" />
</appSettings>
</add>
<add name="prod">
<appSettings>
<add key="SmtpServer" value="global.smtp.com - prod env value" />
<add key="AdServer" value="global.ad.com - prod env value" />
</appSettings>
</add>
</environments>
</global>

While this works, I really want to lose the wrapper elements, and have the
tags named what I want. Is there something built-in that collections must
have members added via an <add> element? I don't see anything in the docs
about this.

William
 
Back
Top