• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9411
  • Last Modified:

Using a Config File with a DLL

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?
0
eternal_21
Asked:
eternal_21
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
0
 
pashcroftCommented:
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.
0
 
eternal_21Author Commented:
Thank you all for your answers!  pashcroft, yours is very helpful, and consistent with the results that I have found.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now