?
Solved

Using a Config File with a DLL

Posted on 2004-10-29
4
Medium Priority
?
9,408 Views
Last Modified: 2011-08-18
How do I use a config file with a C# DLL?

  OR, if you can answer this question:

How do System.Configuration.AppSettingsReader, and System.Configuration.ConfigurationSettings.AppSettings determine a filename to look for the config file?
0
Comment
Question by:eternal_21
4 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12449618
0
 
LVL 4

Accepted Solution

by:
pashcroft earned 2000 total points
ID: 12460094
My understanding is that system.configuration uses the app.config file in the loaded assembly.

I.e. if you have a windows application called myapp.exe that references a dll called mydll.dll, and in the dll you have code to get an appsetting, system.config will use myapp.exe's app.config to find the setting.

in web apps the config file is called web.config.

If you use nunit, and need to use config settings you can put a config file with the same name as the nunit project, ie create a new nunit project called mynunit.nunit, add the mydllTests.dll that references and tests mydll.dll, put a config file called mynunit.config in the same directory as mynunit.nunit and the unit tests that run mydll's AppSettings will get them from myunit.config.

Main key to remember, the main loading assembly's config file (same directory as the exe or web app) is used for all system.configuration operations for all the dependant dlls.
0
 
LVL 10

Author Comment

by:eternal_21
ID: 12462139
Thank you all for your answers!  pashcroft, yours is very helpful, and consistent with the results that I have found.

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question