reading exe app.config from DLL in .NET 2.x

  • Thread starter Thread starter Kevin S Gallagher
  • Start date Start date
K

Kevin S Gallagher

I have been attempting to read a value from the starting executable while in
a DLL.

So far have tried the following were "Test" is a defined value in the EXE.
What is returned is a blank/empty string
System.Configuration.ConfigurationManager.AppSettings.Item("Test")

Did some research on Google but only found people untried suggestions, none
that work in .NET Framework 2.


Any thoughts?

Kevin
 
I have been attempting to read a value from the starting executable
while in a DLL.

So far have tried the following were "Test" is a defined value in the
EXE. What is returned is a blank/empty string
System.Configuration.ConfigurationManager.AppSettings.Item("Test")

Did some research on Google but only found people untried suggestions,
none that work in .NET Framework 2.

That usually works fine for me.

Are you getting a blank value? how does your App.config look like?
 
First thanks for chiming in!!!

Yes I am getting a blank value.
The best way to describe my app.config, enter a name to reference i.e.
"Test" and then enter a string value for "test" i.e. "Hello". I would
copy-n-paste my simple app.config here but needed to more forwards with an
alternate solution until my original question could be solved and now using
XML


This is my solution away from app.config in the DLL until someone can tell
me the correct method to read app.config from a supporting DLL
Public Class ReadConfiguration
Private strLogFile As String
Private strSendToMailAddress As String
Private strFromMailAddress As String
Private strServer As String

''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property LogFile() As String
Get
Return strLogFile
End Get
Set(ByVal value As String)
strLogFile = value
End Set
End Property
Public Property SendToMailAddress() As String
Get
Return strSendToMailAddress
End Get
Set(ByVal value As String)
strSendToMailAddress = value
End Set
End Property
Public Property FromMailAddress() As String
Get
Return strFromMailAddress
End Get
Set(ByVal value As String)
strFromMailAddress = value
End Set
End Property
Public Property Server() As String
Get
Return strServer
End Get
Set(ByVal value As String)
strServer = value
End Set
End Property

Sub New()
If IO.File.Exists("unhandledExceptions.xml") Then
Using ConfigurationFile As New
System.Xml.XmlTextReader("unhandledExceptions.xml")
ConfigurationFile.WhitespaceHandling =
System.Xml.WhitespaceHandling.None
Do While ConfigurationFile.Read()
If ConfigurationFile.NodeType =
System.Xml.XmlNodeType.Element Then
Select Case ConfigurationFile.Name
Case "PrimaryLogFile"
LogFile = ConfigurationFile.ReadString
Case "SendEmailTooAddress"
SendToMailAddress = ConfigurationFile.ReadString
Case "EmailFromAddress"
SendToMailAddress = ConfigurationFile.ReadString
Case "SmtpClientServer"
Server = ConfigurationFile.ReadString
End Select
End If
Loop
End Using
End If

End Sub
End Class


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<UHE>
<PrimaryLogFile>logExceptions.txt</PrimaryLogFile>
<SendEmailTooAddress></SendEmailTooAddress>
<EmailFromAddress></EmailFromAddress>
<SmtpClientServer></SmtpClientServer>
</UHE>
 
Seems like for the lack of response I am discontinuing this path and use my
alternate approach. Thanks for taking the time to at least consider a
solution/
 
I just saw the thread and wanted to chime in that we typically do some custom
config when making a dll, because we don't have any control at times on the
executable that calls our dll. We are making a dll for use by others. In a
case where you control the executables, the app.config does make sense, but
consider cases where a non-dotnet app may use your dll via com. Sometimes
you have to support both these environments.
 
Thanks for your input/thoughts.

ModelBuilder said:
I just saw the thread and wanted to chime in that we typically do some
custom
config when making a dll, because we don't have any control at times on
the
executable that calls our dll. We are making a dll for use by others. In
a
case where you control the executables, the app.config does make sense,
but
consider cases where a non-dotnet app may use your dll via com. Sometimes
you have to support both these environments.
 
Back
Top