473,738 Members | 7,110 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 3783
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
3729
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
22489
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
2287
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
2087
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
2899
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
10322
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
12059
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
8969
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
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9263
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
8210
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
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
6053
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
4570
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.