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:
<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