The app.config file is associated only with an exe, not a dll, so you cannot
have a your.dll.config.
However, from within the dll, you can access settings in app.exe.config.
rajasi
> I have a solution with 2 projects: a class library(my.dll) + a windows
> application (mine.exe). In exe project I have a reference to the dll. In
[quoted text clipped - 3 lines]
>
> Thnx for any advice.
I created this class which lets you create a kind of app.config for dll's
Imports System.Xml
Imports System.Configuration
' usage:
' The xml file must be built like this
'<configuration>
' <assemblySettings>
' <add key="key1" value="Value for key1 (OtherTestLib)"/>
' <add key="key2" value="Value for key2 (OtherTestLib)"/>
' </assemblySettings>
'</configuration>
' Dim settings as AssemblySetting(filename)
' Dim var1 as string = settings("key1")
' Dim var2 as string = settings("key2")
' for enumeration
' Dim settings as IDictionary
' Dim entry as DictionaryEntry
'
' settings = AssemblySetting.GetConfig(filename)
' For Each entry in settings
'
' Next
Public Class AssemblySettings
Private mysettings As IDictionary
Dim entry As DictionaryEntry
Public Sub New(ByVal FileName As String)
mysettings = GetConfig(FileName)
End Sub
Default Public ReadOnly Property KeyValue(ByVal KeyName As String) As String
Get
Dim retVal As Object
If Not mysettings Is Nothing Then
retVal = mysettings(KeyName)
End If
If Not retVal Is Nothing Then
Return CType(retVal, String)
Else
Return ""
End If
End Get
End Property
Shared Function GetConfig(ByVal FileName As String) As IDictionary
Dim doc As XmlDocument = New XmlDocument()
Dim nodes As XmlNodeList
Dim node As XmlNode
doc.Load(FileName)
nodes = doc.GetElementsByTagName("assemblySettings")
For Each node In nodes
If node.LocalName = "assemblySettings" Then Return CType(New
DictionarySectionHandler().Create(Nothing, Nothing, node), IDictionary)
Next
End Function
End Class
> I have a solution with 2 projects: a class library(my.dll) + a windows
> application (mine.exe). In exe project I have a reference to the dll. In
[quoted text clipped - 3 lines]
>
> Thnx for any advice.
chris yoker - 21 Feb 2005 15:12 GMT
hiya,
good solution :-)
I am wondering though, when you call
"GetConfig(ByVal fileName As String) As IDictionary"
..did you have to hard-code the fileName?
Is there a way that I could obtain the filePath without hard-coding?
eg, I know that I can use things like " Application.ExecutablePath" to get
the path of the EXE, but I am obviously using a class library that launches
the EXE, so myClassLibrary:
1) starts the EXE as an external program
2) has the same output path as that of the EXE.
Do I have to hard-code the path of the fileName, or can I use an
"application property" or something siliar, so that I don't have to hard-
code?
make sense?
cheers,
yogi