NeilG

I've created a custom app.config section
<configuration>
    <configSections>
          <sectionGroup name="MySectionGroup">
            <section name="MySectionName" type="ConfigSections.MyConfigHandler, ConfigSections"/>
        </sectionGroup>
    </configSections>

  <MySectionGroup>
    <MySectionName>
      <mytag name="MyName" customfield="customdata"/>
     </MySectionName>
  </MySectionGroup>
  </configuration>

and a custom handler (most of the code from ms how-tos)

Imports System
Imports System.Collections
Imports System.Text
Imports System.Configuration
Imports System.Xml



Namespace ConfigSections
    Public Class MyConfigHandler
        Implements IConfigurationSectionHandler
        Public Function Create(ByVal parent As Object, ByVal configContext As Object, ByVal section As Xml.XmlNode) As Object Implements IConfigurationSectionHandler.Create

            ' Creates the configuration object that this method will return.
            ' This can be a custom configuration class.
            ' In this example, we use a System.Collections.Hashtable.
            Dim myConfigObject As New Hashtable

            ' Gets any attributes for this section element.
            Dim myAttribs As New Hashtable
            For Each attrib As XmlAttribute In section.Attributes
                If XmlNodeType.Attribute = attrib.NodeType Then
                    myAttribs.Add(attrib.Name, attrib.Value)
                End If
            Next

            ' Puts the section name and attributes as the first config object item.
            myConfigObject.Add(section.Name, myAttribs)

            ' Gets the child element names and attributes.
            For Each child As XmlNode In section.ChildNodes
                If XmlNodeType.Element = child.NodeType Then
                    Dim myChildAttribs As New Hashtable

                    For Each childAttrib As XmlAttribute In child.Attributes
                        If XmlNodeType.Attribute = childAttrib.NodeType Then
                            myChildAttribs.Add(childAttrib.Name, childAttrib.Value)
                        End If
                    Next
                    myConfigObject.Add(child.Name, myChildAttribs)
                End If
            Next

            Return (myConfigObject)

        End Function
    End Class
End Namespace



But when I go to call read the data with
 Dim config As New Hashtable
        config = CType(System.Configuration.ConfigurationSettings.GetConfig("MySectionGroup/MySectionName"), Hashtable)


I get an ConfigurationException that it couldn't create ConfigSections.MyConfigHandler

What am I missing



Re: Windows Forms General Custom App.config sections and handler

Basani

NeilG,

I am also having the same problem. I wrote my code in C# and it worked. Then as per my company standards, I am changing my code from C# to VB.NET. I haven't changed anything as far as the config file is concerned.

I get a ConfigurationException that it couldn't create my handler.

<configSections>

<section name="TypeSubTypeSection" type="MyNamespace.TypeSubTypeSectionHandler, MyNamespace" />

</configSections>

Did you resolve your problem

Thanks & Regards
Basani





Re: Windows Forms General Custom App.config sections and handler

Zhi-Xin Ye - MSFT

Hi,the above

This sample may help you much.

Regards.