How to access ApplicationSettings section from another assembly?

I have a dll referenced by the parent (executing) assembly. In the ApplicationSettings app.config section for the parent assembly, I have some options that can be accessed in the usual intellisense way (e.g. Properties.Settings.Default.SMTPServer).

How to access these settings from a reference DLL? I obviously can't use intellisense as they are not in the same assembly!

+4
source share
2 answers

Do you access this value from both assemblies?

The dll may have its own configuration file and application settings. It starts as a dll with a configuration file named after it, but the settings can also be moved to the main application.

The other approach that I used assigns an IoC value and then reads the value from Ioc (Ioc == Inversion of Control library). You can do the same by assigning a value to a singleton class.

0
source

Have you tried saving the .settings file in your DLL project, and then using your operator [] to access the property by name?

For example, let's say your DLL has a MySettings.settings file that has nothing special in it:

MySettings.Default ["SomeSetting"];

(Notice, I have not actually tried this, but upon thinking it seems like it should work)

I think the best solution would be to take Chrisโ€™s advice and use a singleton or IOC mechanism, so you donโ€™t have to sacrifice type safety.

0
source

All Articles