Click here to Skip to main content
Click here to Skip to main content

DLL with configuration file

By , 22 May 2011
Rate this:
Please Sign up or sign in to vote.
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

Brazil Brazil
I'm a system analyst (senior) and I live in Belo Horizonte, Minas Gerais, Brazil. I've been working with software development since 1996.

Comments and Discussions

QuestionNot working when updating config file values Pinmemberxyz from Bangalore20-Oct-13 18:50 
GeneralMy vote of 5 Pinmemberremi22211-Jul-13 7:27 
QuestionNot work in WebApplication [modified] PinmemberMlsoun1-Oct-12 2:04 
AnswerRe: Not work in WebApplication PinmemberFregate19-Feb-13 16:03 
GeneralRe: Not work in WebApplication Pinmemberfmsalmeida20-Feb-13 0:12 
GeneralRe: Not work in WebApplication PinmemberFregate20-Feb-13 12:15 
GeneralRe: Not work in WebApplication Pinmembereng_george128-Jan-14 1:30 
QuestionVS10 Saves Setting to Project.dll.config PinmemberMember 462571327-Mar-12 5:24 
GeneralReason for my vote of 5 This solved a problem that I've been... Pinmemberjtdavies8-Feb-12 8:54 
GeneralReason for my vote of 5 Nice, I like it, and I am bookmarkin... PinmemberFDW3-Nov-11 1:06 
Reason for my vote of 5
Nice, I like it, and I am bookmarking it Smile | :)
GeneralReason for my vote of 5 It is very good :) PinmemberCaner Korkmaz23-Aug-11 0:14 
GeneralReason for my vote of 5 Bookmarked for future ref. PinmemberKeithAMS2-Jun-11 22:40 
QuestionPossible in .NET 1.1? PinmemberKeithAMS27-Oct-11 23:28 
AnswerRe: Possible in .NET 1.1? Pinmemberfmsalmeida28-Oct-11 3:18 
GeneralGood Tip PinmemberKeithAMS2-Jun-11 22:40 
GeneralRe: Good Tip Pinmemberfmsalmeida3-Jun-11 2:32 
GeneralExplain why.... PinmemberEngleA27-May-11 3:28 
GeneralRe: Explain why.... Pinmemberfmsalmeida27-May-11 4:16 
QuestionToo complex? PinmemberRiz Thon23-May-11 20:03 
AnswerRe: Too complex? Pinmemberfmsalmeida24-May-11 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.140421.2 | Last Updated 22 May 2011
Article Copyright 2011 by fmsalmeida
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid