Custom Configuration Section - .NET 2.0

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top