473,698 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Configuration File Question

Ian
I have an application called "Test.exe" and this application has a config
file called "Test.exe.confi g" and it holds the connection string for the
database calls in there. To get the conectionstring out of the config file
the following lines of code are utilized.

Private settings As New System.Configur ation.AppSettin gsReader
Private o As Object = settings.GetVal ue("ConnectionS tring", GetType(String) )
Private strConnection As String = o.ToString()

This works fine.... But I also have an exception assembly that I imported
into this application "Test.exe". The assembly is called
"CallExceptionH andling.dll" and it also has a config file called
"CallExceptionH andling.dll.con fig" and inside sits the connectionstrin g that
pertains to the generic exception handler assembly. The code used in the
assembly to get the connectionstrin g is the same code as used for the
application.

But when I run the application and the exception assembly goes and gets the
connectionstrin g it is looking to the "Test.exe" config file and not the dll
config file.

Where am I going wrong?

Thanks
Jul 21 '05 #1
1 3781
Hello Ian,

Thanks for your post. I'd like to share the following information with you:

1. Generally speaking, DLLs do not have config files in a .NET application.
Rather, they share the configuration information of the EXE that is being
used. Because the AppDomainSetup. ConfigurationFi le specifies the EXE.Config
by default. The AppSettingsRead er class reads the application settings when
the default AppDomain is loaded, and then those settings are cached for the
lifetime of the AppDomain.

2. Based on my experience and research, there are two methods to work
around this problem:

Method 1
========
I strongly recommend you create a custom Application Configuration class
which loads the configuration from another file. The following code snippet
demonstrate load a .Config file and deserialize XML to get the value:

//-----------------code snippet-------------------
// Create an XmlSerializer for the ApplicationSett ings type.
mySerializer = new XmlSerializer(t ypeof(Applicati onSettings));
FileInfo fi = new FileInfo(Applic ation.LocalUser AppDataPath
+ @"\CallExceptio nHandling.dll.c onfig");
// If the config file exists, open it.
if(fi.Exists)
{
myFileStream = fi.OpenRead();
// Create a new instance of the ApplicationSett ings by
// deserializing the config file.
ApplicationSett ings myAppSettings =
(ApplicationSet tings)mySeriali zer.Deserialize (
myFileStream);
// Assign the property values to this instance of
// the ApplicationSett ings class.
String myConnectionStr ing = myAppSettings.C onnectionString ;
}
//----------------end of ----------------------

I believe the article below is very helpful:

Persisting Application Settings in the .NET Framework
http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/persistappsettn et.asp

Method 2
========
Another method is to create a new AppDomain with the
AppDomainSetup. ConfigurationFi le set to "CallExceptionH andling.dll.con fig",
and run the dll in the new AppDomain.

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #2

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

Similar topics

10
3719
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server Error in '/QuickStartv20' Application. -------------------------------------------------------------------------------- Configuration Error Description: An error occurred during the processing of a configuration file
7
22486
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We added an entry to the executable's .exe.config file to specify the URL, and under the 1.1 framework this worked well. Unfortunately, this is not working under the 2.0 framework. I see in the Reference.cs file under the web service reference the...
5
2933
by: Hardy Wang | last post by:
Hi all, I understand, in .Net 2.0 we have little bit different model to read config file from .Net 1.1. Basically I need to use WebConfigurationManager.AppSettings to read from web.config, and ConfigurationManager.AppSettings to read from Windows Application config. Here is my question, I have a class library project which will be referenced by both Web and Windows Application in different projects, I need to read config setting inside...
9
2283
by: KarlM | last post by:
After reading some articles regarding confuguration data I'm a bit confused. Where is the right place for storing configuration data? - XML-files? - registry? - INI-files? (from a users point of view, ini-files are more comfortable to read and edit) Where should I store user specific config data? Where should I store machine specific config data?
5
2083
by: Jay | last post by:
I want to store various text settings in a configuration file, that I will read into C# and make use of. Here's a simplified example of the file: #comment loop(var=1:5){ deviceundertest freq:5.6e6 power:3.7 analyser freq:5.6e6 span:1e3 resbw:100 atten:20 } As you can see, the configuration file will define:
9
2897
by: shror | last post by:
hi every body, i have a problem which is when i was checking my mail() form it work fine but the problem is that the form configuration is not set correctly, in details: the from var is not working and the from is set to be my host provider email is the sender, so they told me to configure the php.ini file and i dont know what is this file and how to configure it. thanks in advance
7
10320
by: Peter Bradley | last post by:
OK. A bit behind the times, I know; but we're just moving over to .NET 2.0. How on earth do you manage configuration settings in a class library in .NET 2.0? In version 1.1, we used a handy class called AssemblySettings that someone (I forget his name) had written. When the class library was finished, you deployed it to the GAC and put the configuration files in the GAC with the class library assembly. This no longer works. In fact...
3
12056
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (machine.config) ---> System.Security.SecurityException: Request for the permission of type
3
2223
by: guybenron | last post by:
Hey, I have a sort of petty-neurotic question, I'm kinda pedantic and like to keep my log directories clean, and this thing is bothering me to the point of actually posting a question (couldn't find any post about this..). My application has two types of components: daemons and regular ones that are run every on crontab. Because the log structure is very similar, I want both to use the same logging configuration file.
5
2082
by: Author | last post by:
This may sound like a silly question. I rarely do console or windows form applications. In a console application, I have an XML configuration file. I place it under my application root. In my code, I also say string configFilePath = "./configuration.xml"; When I debug the application with VS 2005, I get an error which says
0
8683
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9031
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.