Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Using a Config File with a DLL

Posted on 2004-10-29
Medium Priority
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?
Question by:eternal_21
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12449618

Accepted Solution

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.
LVL 10

Author Comment

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


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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