加载自定义配置节的文件或程序集时出错 [英] Getting Error loading file or assembly for custom Config Section
问题描述
大家好,
我继承了一些我需要扩展的VB代码.我对VB的经验很少,我通常使用C#.所以我需要帮助!
我正在尝试将自定义部分添加到App.config文件中.本节将为供应商提供多个要素.如下:
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
然后,在我的代码中,我有另一个名为SupplierInfo的类,它以列表的形式变暗,并且按如下方式使用它:
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")
那就是向我抛出错误的地方.我收到此错误消息; 为supplierInfo创建配置节处理程序时发生错误:无法从程序集"System.Configuration,版本= 2.0.0.0,区域性= neutral,PublicKeyToken =…"中加载类型"SupplierInfoSection"."
如何使它正确加载?
我们将一如既往地为您提供帮助.谢谢
Eric
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
推荐答案
讨厌回答我自己的问题,但这可以解决我遇到的错误.正在寻找完全限定的名称
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.
这篇关于加载自定义配置节的文件或程序集时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!