I just recently needed this functionality so here's the class I made to
accomplish it:
Imports System.Collecti ons.Specialized
Imports System.Reflecti on.Assembly
Public Class AssemblyConfigu rationSettings
Public Shared ReadOnly Property AppSettings() As NameValueCollec tion
Get
Dim filename As String = GetCallingAssem bly.Location & ".config"
Dim settings As New NameValueCollec tion
If Not System.IO.File. Exists(filename ) Then
Return settings
End If
Try
Dim reader As New System.Xml.XmlT extReader(filen ame)
Dim doc As New System.Xml.XmlD ocument
doc.Load(reader )
Dim configurationNo de As System.Xml.XmlN ode =
doc.SelectSingl eNode("configur ation")
If configurationNo de Is Nothing Then
Return settings
End If
Dim appSettingsNode As System.Xml.XmlN ode =
configurationNo de.SelectSingle Node("appSettin gs")
If appSettingsNode Is Nothing Then
Return settings
End If
Dim nodes As System.Xml.XmlN odeList =
appSettingsNode .SelectNodes("a dd")
For Each node As System.Xml.XmlN ode In nodes
settings.Add(no de.Attributes(" key").Value,
node.Attributes ("value").Value )
Next
Catch ex As System.Xml.XmlE xception
End Try
Return settings
End Get
End Property
End Class
/claes
"Phill W." <p-***********@o-p-e-n.a-c.u-k> wrote in message
news:e0******** **@yarrow.open. ac.uk...
"Søren M. Olesen" <sm******@hotma il.com> wrote in message
news:e0******** ******@TK2MSFTN GP11.phx.gbl...
However when I use this class library, it doesn't seem to read the
settings myClasses.dll.c onfig file, instead I just get then initial
values I used when creating the settings.settin gs section.
I've only ever seen these values read from an Application.EXE .config
which, annoyingly, means you have to ship these settings in every
application that uses your library.
Or, in a web application, (I think) these settings are read from the
web.config file.
HTH,
Phill W.