Click here to Skip to main content
11,929,249 members (56,370 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked

DLL with configuration file

, 22 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Using configuration files in DLL is not trivial, but is very simple.
Using configuration files in DLL is not trivial.
To accomplish this, we must follow these steps:
  • Add a reference to System.Configuration
  • Add a new Application Configuration File and the name it [Your project].dll.config
  • Change the BuildAction property of the config file to Content
  • Change the Copy to Output property to "Copy Always"

After these steps, you can access the configuration file this way:
//Open the configuration file using the dll location
Configuration myDllConfig = 
// Get the appSettings section
AppSettingsSection myDllConfigAppSettings = 
// return the desired field 
return myDllConfigAppSettings.Settings["MyAppSettingsKey"].Value; 

Your configuration file should look like this:
<?xml version="1.0" encoding="utf-8" ?>
    <add key ="MyAppSettingsKey" value="MyValue"/>

That's all. Hope you enjoy this tip.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ireland Ireland
I'm a Brazilian senior system analyst living in Limerick, Ireland. I've been working with software development since 1996.

You may also be interested in...

Comments and Discussions

QuestionNot work in WebApplication Pin
Mlsoun1-Oct-12 3:04
memberMlsoun1-Oct-12 3:04 
AnswerRe: Not work in WebApplication Pin
Fregate19-Feb-13 17:03
memberFregate19-Feb-13 17:03 
GeneralRe: Not work in WebApplication Pin
fmsalmeida20-Feb-13 1:12
memberfmsalmeida20-Feb-13 1:12 
GeneralRe: Not work in WebApplication Pin
Fregate20-Feb-13 13:15
memberFregate20-Feb-13 13:15 
GeneralRe: Not work in WebApplication Pin
eng_george128-Jan-14 2:30
membereng_george128-Jan-14 2:30 
GeneralRe: Not work in WebApplication Pin
Member 348500310-Apr-15 5:33
memberMember 348500310-Apr-15 5:33 
GeneralRe: Not work in WebApplication Pin
Member 112799398-May-15 8:25
memberMember 112799398-May-15 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 22 May 2011
Article Copyright 2011 by fmsalmeida
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid