473,569 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.Configur ation.Configura tionManager.App Settings.Item(" Test")

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

Kevin
Jul 31 '07 #1
5 3834
"Kevin S Gallagher" <ke************ ***@state.or.us wrote in
news:er******** ******@TK2MSFTN GP04.phx.gbl:
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.Configur ation.Configura tionManager.App Settings.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?
Jul 31 '07 #2
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 ReadConfigurati on
Private strLogFile As String
Private strSendToMailAd dress As String
Private strFromMailAddr ess 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 SendToMailAddre ss() As String
Get
Return strSendToMailAd dress
End Get
Set(ByVal value As String)
strSendToMailAd dress = value
End Set
End Property
Public Property FromMailAddress () As String
Get
Return strFromMailAddr ess
End Get
Set(ByVal value As String)
strFromMailAddr ess = 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( "unhandledExcep tions.xml") Then
Using ConfigurationFi le As New
System.Xml.XmlT extReader("unha ndledExceptions .xml")
ConfigurationFi le.WhitespaceHa ndling =
System.Xml.Whit espaceHandling. None
Do While ConfigurationFi le.Read()
If ConfigurationFi le.NodeType =
System.Xml.XmlN odeType.Element Then
Select Case ConfigurationFi le.Name
Case "PrimaryLogFile "
LogFile = ConfigurationFi le.ReadString
Case "SendEmailTooAd dress"
SendToMailAddre ss = ConfigurationFi le.ReadString
Case "EmailFromAddre ss"
SendToMailAddre ss = ConfigurationFi le.ReadString
Case "SmtpClientServ er"
Server = ConfigurationFi le.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>
<SendEmailTooAd dress></SendEmailTooAdd ress>
<EmailFromAddre ss></EmailFromAddres s>
<SmtpClientServ er></SmtpClientServe r>
</UHE>

"Spam Catcher" <sp**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"Kevin S Gallagher" <ke************ ***@state.or.us wrote in
news:er******** ******@TK2MSFTN GP04.phx.gbl:
>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.Configu ration.Configur ationManager.Ap pSettings.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?

Jul 31 '07 #3
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/

"Kevin S Gallagher" <ke************ ***@state.or.us wrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
>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.Configur ation.Configura tionManager.App Settings.Item(" Test")

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

Kevin

Aug 1 '07 #4
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.

"Kevin S Gallagher" wrote:
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/

"Kevin S Gallagher" <ke************ ***@state.or.us wrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
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.Configur ation.Configura tionManager.App Settings.Item(" Test")

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

Kevin


Aug 2 '07 #5
Thanks for your input/thoughts.

"ModelBuild er" <Mo**********@d iscussions.micr osoft.comwrote in message
news:AF******** *************** ***********@mic rosoft.com...
>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.

"Kevin S Gallagher" wrote:
>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/

"Kevin S Gallagher" <ke************ ***@state.or.us wrote in message
news:er******* *******@TK2MSFT NGP04.phx.gbl.. .
>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.Configur ation.Configura tionManager.App Settings.Item(" Test")

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

Kevin



Aug 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2046
by: Sami | last post by:
Hello, I have this problem that I need your help with : I am reading a config file that contain the following : 2004 update
3
2415
by: spacekid | last post by:
Hi there I am exposing a c# assembly as a COM component (regasm /codebase) and calling it from classic asp. When I try to call the ConfigurationSettings.AppSettings function in the c# assembly, it does not return the values from my web.config. The web.config is located in the root of the web application. The classic asp page that calls...
2
5088
by: news.microsoft.com | last post by:
Hi After conducting a several searches, I wasn't sure where to post this question. So my apologiesbefore hand for double posting this and possibly posting to the wrong forum(s). Okay, I have any application that uses the data access application building block from Microsoft's Enterprise Library (patterns and practices site). I want to...
1
1683
by: comic_rage | last post by:
Hi, I am trying to read from my application config file and keep getting null. Here is my config file My application is called SampleApp.exe
10
9428
by: Ryan | last post by:
I've created a custom configuration section that inherits (naturally) from System.Configuration.ConfigurationSection. The configuration section is working 99% fine, however I keep coming across a ConfigurationErrorException whenever I do the following: 1. Modify and save the section in code using the...
2
1543
by: marek zegarek | last post by:
Hello! On my server I have Sharepoint portal server as default web site I create there a web application folder with form.aspx file. When I'm trying to run aspx, i get an error. Page is trying to read config from x:\inetpub\wwwroot\web.config. Correct path is x:\inetpub\wwwroot\test\web.config. How to force on application (or IIS or...
5
10328
by: alf | last post by:
Hi folks, I'm trying to read a web.config section using RoleManagerSection settings = (RoleManagerSection)System.Configuration.ConfigurationManager.GetSection("system.web/roleManager"); and I get the following error on the page: Security Exception Description: The application attempted to perform an operation not allowed
9
2705
by: Milsnips | last post by:
Hi all. i'm tryng to implement the Rewrite.NET url rewritining functionality into a test project i've created, however i am hitting a problem at this line (direct from the web example): System.Collections.Specialized.NameValueCollection SectionIndex =...
1
7474
by: M Irfan | last post by:
Hello all, Recently I have started working in .NET 2.0. I am developing a web service application that references a DLL component written in C# 2.0. The component has its own config file which contains settings related to business logic coded in that component. I can reference and load the component but unable to read load the custom config...
1
2245
by: vijayarl | last post by:
Hi Everyone, i have the written this logic : basically a file operation open (CONFIGFILE, "$config_file") or die; while (<CONFIGFILE>) { chomp;
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.