Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi All,

I’ve inherited some VB code that I need to expand. I have very little experience with VB I usually work with C#. So I need help!!

I’m trying to add a custom section to the App.config file. This section will content multiple elements for suppliers. As follows:

XML
<configSections>
  <section name="supplierInfo" type="SupplierInfoConfigurationHandler" allowLocation="true" allowDefinition="Everywhere" />
</configSections>

<supplierInfo>
  <Supplier supplierid="1" loadnumber="45" paddedloadnumber="000000000045" />
  <Supplier supplierid="2" loadnumber="95" paddedloadnumber="000000000095" />
</supplierInfo>


I found and modified some code for the handler class as follows:

Imports System
Imports System.IO
Imports System.Configuration
Imports System.Collections
Imports System.Xml
Imports Microsoft.VisualBasic

'Namespace FileConverter
Public Class SupplierInfoConfigurationHandler
    Implements IConfigurationSectionHandler

    Public SupplierInfoConfigurationHandler()

    Public Function Create(ByVal parent As Object, ByVal configContext As Object, ByVal section As System.Xml.XmlNode) As Object Implements System.Configuration.IConfigurationSectionHandler.Create
        Dim items As New List(Of SupplierInfo)
        Dim processesNodes As System.Xml.XmlNodeList

        processesNodes = section.SelectNodes("Supplier")

        For Each processNode As System.Xml.XmlNode In processesNodes
            Dim item As New SupplierInfo

            item.SupplierID = processNode.Attributes.ItemOf("supplierid").InnerText
            item.LoadNumber = processNode.Attributes.ItemOf("loadnumber").InnerText
            item.PaddedLoadNumber = processNode.Attributes.ItemOf("paddedloadnumber").InnerText
            items.Add(item)
        Next

        Return items
    End Function
End Class


Then in my code I have another class called SupplierInfo that I Dim as a List and I use it as follows:

SuppliersInfo = System.Configuration.ConfigurationManager.GetSection("supplierInfo")



That’s where it throws an error on me. I get this error message; “An error occurred creating the configuration section handler for supplierInfo: Could not load type 'SupplierInfoSection' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=…'.”

How do I get this to load properly?

Your help as always will be greatly appreciated. Thanks

Eric
Posted

1 solution

Hate to answer my own question but this seams to resolve the error I'm getting. It's looking for a fully qualified name

<section name="supplierInfo" type="ASSEMBLYNAME.NAMESPACE.SupplierInfoConfigurationHandler, ASSEMBLYNAME.NAMESPACE" allowlocation="true" allowdefinition="Everywhere" />


I still have issues to work out. Thanks everyone for looking.
 
Share this answer
 
Comments
Nelek 19-Apr-12 18:27pm    
You should not hate answering your own question, first of all it implies that you are really working on your code (what make other users more receptive to answer you in future questions). Second, you might have found a solution, but maybe other user read it and give you a better option, so you can improve your code and still learn more.
I see nothing wrong with it, just the opposite :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900