By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,743 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,743 IT Pros & Developers. It's quick & easy.

customer configuration

P: n/a
My Windows Application stores its configuration values in app.config and
these are typed and accessed via corresponding classes, something like this...

<section name="Watcher"/>

<add Name="Blah"/>

Friend Class Watcher

Inherits System.Configuration.ConfigurationSection

<System.Configuration.ConfigurationProperty("Clock WatcherCollection",
Friend ReadOnly Property ClockWatcherCollection() As
Return Me("ClockWatcherCollection")
End Get
End Property

End Class

Friend Class ClockWatchCollection

Inherits System.Configuration.ConfigurationElementCollectio n

Protected Overloads Overrides Function CreateNewElement() As
Return New ClockWatch
End Function

Protected Overrides Function GetElementKey(ByVal Element As
System.Configuration.ConfigurationElement) As Object
Return CType(Element, ClockWatch).Name
End Function

Friend Shadows Function Item(ByVal Name As String) As ClockWatch
Return MyBase.BaseGet(Name)
End Function

End Class

Friend Class ClockWatch

Inherits System.Configuration.ConfigurationSection

<System.Configuration.ConfigurationProperty("Name" , IsRequired:=True)_
Friend ReadOnly Property Name() As String
Return Me("Name")
End Get
End Property

End Class

This works fine for simple types, such as the Name property above, but I
can’t see how to do the same for complex types like the collection of
Notification types and the LogFile type below…

<add Name="Blah">
<Notification Address="Blah"/>
<Notification Address="Blah"/>
<Notification Address="Blah"/>
<LogFile Name="Blah", MaxSize="Blah", Delete="Blah"/>
May 18 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Dick,

From your description, you're wantting to add some custom configuration
section to the applicaiton config file, and some of the configure element
contains item collections, and you met some problem to get complex type
collection in the custom configsection, correct?

Based on my understanding, the .net framework 2.0 custom configuration
interface support two kinds of custom configuration handler:

1. derive your custom configuration section class from
"ConfigurationSection" class, and any sub property/section from
"ConfigurationElement" or "ConfigurationElementCollection". And if you
want to add custom item collection this way, you can only contains a single
type of element in one colleciton and use "<add>", "<remove>" element to
add or remove item. e.g.

<clear />
name="Microsoft" url="" port="0"
lockAllAttributesExcept="port" />
name="Contoso" url="" port="8080"
lockAllAttributesExcept="port" lockItem="true" />

and it only support simple/basic types rather than nested complex
2. For your scenario, if you want to add complex nested properties for each
item in configuration colleciton/list, I'm afraid you may need to write a
custom section handler and use raw XML API or XML serialization api to
manage the XML content of the section directly. see the following MSDN

#How to: Create Custom Configuration Sections Using


Steven Cheng

Microsoft MSDN Online Support Lead


Get notification to my posts through email? Please refer to

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at


This posting is provided "AS IS" with no warranties, and confers no rights.

May 21 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.