Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing custom configuration section handler
    primarykey
    data
    text
    <p>gleanings from a variety of sources (including stackOverlflow), however when I come to use it, I get the following error message</p> <p>"The Configuration property 'deviceconfig' may not be derived from ConfigurationSection."</p> <p>I have been struggling with this for the better part of a day now, and am no nearer a solution, so any help in the matter would be greatly appreciated. I am a newbie in implementing custom config sections so please treat me gently :-)</p> <p>The app.config file looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;configSections&gt; &lt;section name="deviceconfig" type="CNIMonitor.Core.CustomConfig.DeviceConfig,Core"/&gt; &lt;/configSections&gt; &lt;system.diagnostics&gt; &lt;sources&gt; &lt;!-- This section defines the logging configuration for My.Application.Log --&gt; &lt;source name="DefaultSource" switchName="DefaultSwitch"&gt; &lt;listeners&gt; &lt;add name="FileLog"/&gt; &lt;!-- Uncomment the below section to write to the Application Event Log --&gt; &lt;!--&lt;add name="EventLog"/&gt;--&gt; &lt;/listeners&gt; &lt;/source&gt; &lt;/sources&gt; &lt;switches&gt; &lt;add name="DefaultSwitch" value="Information" /&gt; &lt;/switches&gt; &lt;sharedListeners&gt; &lt;add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/&gt; &lt;!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --&gt; &lt;!--&lt;add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/&gt; --&gt; &lt;/sharedListeners&gt; &lt;/system.diagnostics&gt; &lt;deviceconfig&gt; &lt;devices&gt; &lt;device deviceid = "1" name = "localhost" ipaddress="127.0.0.1" port="10000" status="not listening" message="no message" /&gt; &lt;device deviceid ="2" name ="2nd localhost" ipaddress="127.0.0.1" port="20000" status="not listening" message="no message" /&gt; &lt;/devices&gt; &lt;/deviceconfig&gt; </code></pre> <p></p> <p>The Custom Section Handler code as follows:</p> <pre><code>Imports System.Configuration </code></pre> <p>Namespace CNIMonitor.Core.CustomConfig</p> <pre><code>Public Class DeviceConfig Inherits ConfigurationSection &lt;ConfigurationProperty("deviceconfig")&gt; _ Public ReadOnly Property DeviceConfig() As DeviceConfig Get Return CType(MyBase.Item("deviceconfig"), DeviceConfig) End Get End Property End Class &lt;ConfigurationCollectionAttribute(GetType(Device))&gt; _ Public Class Devices Inherits ConfigurationElementCollection Protected Overrides Function CreateNewElement() As ConfigurationElement Return New Device End Function Protected Overrides Function GetElementKey _ (ByVal element As ConfigurationElement) As Object Return CType(element, Device).DeviceID End Function Public Sub Add(ByVal element As Device) Me.BaseAdd(element) End Sub End Class Public Class Device Inherits ConfigurationElement &lt;ConfigurationProperty("deviceid", DefaultValue:="", IsKey:=True, IsRequired:=True)&gt; _ Public Property DeviceID() As String Get Return CType(MyBase.Item("deviceid"), String) End Get Set(ByVal value As String) MyBase.Item("deviceid") = value End Set End Property &lt;ConfigurationProperty("hostname", DefaultValue:="", IsKey:=True, IsRequired:=False)&gt; _ Public Property HostName() As String Get Return CType(MyBase.Item("RegisteredDate"), String) End Get Set(ByVal value As String) MyBase.Item("RegisteredDate") = value End Set End Property &lt;ConfigurationProperty("ipaddress", DefaultValue:="", IsKey:=True, IsRequired:=False)&gt; _ Public Property IpAddress() As String Get Return CType(MyBase.Item("ipaddress"), String) End Get Set(ByVal value As String) MyBase.Item("ipaddress") = value End Set End Property &lt;ConfigurationProperty("port", DefaultValue:="", IsKey:=True, IsRequired:=False)&gt; _ Public Property Port() As String Get Return CType(MyBase.Item("port"), String) End Get Set(ByVal value As String) MyBase.Item("port") = value End Set End Property &lt;ConfigurationProperty("status", DefaultValue:="", IsKey:=False, IsRequired:=False)&gt; _ Public Property Status() As String Get Return CType(MyBase.Item("status"), String) End Get Set(ByVal value As String) MyBase.Item("status") = value End Set End Property &lt;ConfigurationProperty("message", DefaultValue:="", IsKey:=False, IsRequired:=False)&gt; _ Public Property Message() As String Get Return CType(MyBase.Item("message"), String) End Get Set(ByVal value As String) MyBase.Item("message") = value End Set End Property End Class End Namespace </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload