PC Review


Reply
Thread Tools Rate Thread

Custom Configuration Section - .NET 2.0

 
 
=?Utf-8?B?V2lsbGlhbSBMZWFyeQ==?=
Guest
Posts: n/a
 
      22nd Nov 2005
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2lsbGlhbSBMZWFyeQ==?=
Guest
Posts: n/a
 
      22nd Nov 2005
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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save changes for a custom configuration section Giulio Petrucci Microsoft C# .NET 1 10th Mar 2010 01:49 PM
Custom Configuration Section partysingh Microsoft ASP .NET 1 27th Jan 2010 04:14 PM
Custom Configuration Section Help Yan Yi Huang Microsoft Dot NET Framework 1 22nd Nov 2007 11:39 AM
Custom Configuration Section Inheritance =?Utf-8?B?UGhpbGlw?= Microsoft ASP .NET 0 27th Sep 2007 04:33 PM
Declaring custom configuration section. Mauricio Microsoft ASP .NET 3 22nd Aug 2003 08:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:53 AM.