473,382 Members | 1,204 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,382 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 3756
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.