Search code examples
c#.netapplication-settings

Why wont my application read my MyApplication.dll.config file?


I'm trying to use application settings with a C#.NET project I am working on. But I can't seem to get it to return anything other then the default values. Through the project properties I've added a single setting, DBConnectionString, and set its value to a connection string I want to use. Its scope is set to "application".

Doing this created a number of files including Settings.settings, Settings.Designer.CS, and app.conifg. From what I understand the two Settings.* files define a custom Settings class that derives from ApplicationSettingsBase. The Settings class then has custom, type safe, properties that can be used to set and retrieve each setting. The app.config file is a XML file that stores the actual settings values.

When I build my project it looks like the app.config file is copied to the target directory as MyApplication.dll.config. My program runs fine and is able to use the default connection string.

Next I tried to edit the MyApplicaiton.dll.config file to change the connection string. I ran my program again, but it continued to use the default value. I noticed that in my Settings.Designer file there is a DefaultSettingValueAttribute with the original default string. I tried removing this attribute, but then when I tried to retrieve the connection string setting it just returned null.

This is the code I'm using to read the connection string.

string conn = Properties.Settings.Default.DbConnectionString

What am I doing wrong? How can I get it to return the value in the settings file and not the default value?


Update:

Sorry I should have mentioned this. I'm actually writing a plug-in for another application through a public API. So my project is a DLL not an EXE.


Solution

  • You cannot read settings from *.dll.config files. If you library needs any special settings you need to put them in your app.config or web.config files.

    EDIT: You can include the external config files in the main application or web config file. Look here for details.

    This question discusses how to manage configuration files for large projects.