Custom config section handler can't find handler
我正在用我的自定义处理程序abramain.myconfigHandler在app.config中创建配置。
错误:
无法从程序集"system.configuration,version=4.0.0.0,culture=neutral,publicKeyToken=b03f5f7f11d50a3a"加载类型"abramain.myconfigHandler.applicationListCollection"。
App.CONFIG1 2 3 4 5 6 7 8 9 | <configuration> <configSections> <section name="applicationList" type ="AbraMain.MyConfigHandler.ApplicationListCollection"/> </configSections> </applicationList> </configuration> |
myconfighandler.vb版
命名空间MyConfigHandler
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 'Desc : Individual Application configuration Class 'Handle Tag : App.config -> -> Public Class ApplInfoConfig Inherits ConfigurationElement <ConfigurationProperty("name", IsRequired:=True)> _ Public Property name() As String Get Return CStr(Me("name")) End Get Set(ByVal value As String) Me("name") = value End Set End Property <ConfigurationProperty("desc", DefaultValue:="", IsRequired:=False)> _ Public Property desc() As String Get Return CStr(Me("desc")) End Get Set(ByVal value As String) Me("desc") = value End Set End Property <ConfigurationProperty("subPath", DefaultValue:="", IsRequired:=False)> _ Public Property subPath() As String Get Return CStr(Me("subPath")) End Get Set(ByVal value As String) Me("subPath") = value End Set End Property <ConfigurationProperty("index", IsRequired:=True)> _ Public Property index() As Integer Get Return Me("index") End Get Set(ByVal value As Integer) Me("index") = value End Set End Property <ConfigurationProperty("iconIndex", DefaultValue:="0", IsRequired:=False)> _ Public Property iconIndex() As Integer Get Return Me("iconIndex") End Get Set(ByVal value As Integer) Me("iconIndex") = value End Set End Property End Class 'Desc : Collection of Individual Application configuration Class 'Handle Tag : App.config -> Public Class ApplicationListCollection Inherits ConfigurationElementCollection Protected Overloads Overrides Function CreateNewElement() As System.Configuration.ConfigurationElement Return New ApplInfoConfig() End Function Protected Overrides Function GetElementKey(ByVal element As System.Configuration.ConfigurationElement) As Object Return CType(element, ApplInfoConfig).name() End Function End Class End Namespace |
问题似乎出在您为自定义部分指定处理程序的行上的
1 | <section name="applicationList" type ="AbraMain.MyConfigHandler.ApplicationListCollection"/> |
自定义处理程序类型的类型声明还需要包含可在其中找到它的程序集。否则,它将尝试在默认的
因此,您也可以通过包含程序集的名称来解决问题。我假设你们的集会叫以东十一〔二〕。然后您需要将该行更改为:
1 | <section name="applicationList" type ="AbraMain.MyConfigHandler.ApplicationListCollection, AbraMain"/> |
不过,您似乎还有第二个问题。对于配置部分,需要有一个实现
因此,需要添加一个新类来执行此操作:
2然后指向你的
1 | <section name="applicationList" type ="AbraMain.MyConfigHandler.ApplicationList, AbraMain"/> |