473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Configuration File Question

Ian
I have an application called "Test.exe" and this application has a config
file called "Test.exe.config" 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.Configuration.AppSettingsReader
Private o As Object = settings.GetValue("ConnectionString", 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
"CallExceptionHandling.dll" and it also has a config file called
"CallExceptionHandling.dll.config" and inside sits the connectionstring that
pertains to the generic exception handler assembly. The code used in the
assembly to get the connectionstring is the same code as used for the
application.

But when I run the application and the exception assembly goes and gets the
connectionstring 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 3752
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.ConfigurationFile specifies the EXE.Config
by default. The AppSettingsReader 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 ApplicationSettings type.
mySerializer = new XmlSerializer(typeof(ApplicationSettings));
FileInfo fi = new FileInfo(Application.LocalUserAppDataPath
+ @"\CallExceptionHandling.dll.config");
// If the config file exists, open it.
if(fi.Exists)
{
myFileStream = fi.OpenRead();
// Create a new instance of the ApplicationSettings by
// deserializing the config file.
ApplicationSettings myAppSettings =
(ApplicationSettings)mySerializer.Deserialize(
myFileStream);
// Assign the property values to this instance of
// the ApplicationSettings class.
String myConnectionString = myAppSettings.ConnectionString;
}
//----------------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/persistappsettnet.asp

Method 2
========
Another method is to create a new AppDomain with the
AppDomainSetup.ConfigurationFile set to "CallExceptionHandling.dll.config",
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
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...
7
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...
5
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...
9
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...
5
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 ...
9
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...
7
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...
3
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...
3
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...
5
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.