Using a Config File with a DLL

Posted on 2004-10-29
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
    LVL 22

    Expert Comment

    LVL 8

    Expert Comment

    LVL 4

    Accepted Solution

    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

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Suggested Solutions

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now