Dennis Kassel
Dennis Kassel

Reputation: 2786

Using "My.Settings" across different assemblies

There are many topics available about using the My.Settings object, but I couldn't find anyone which addresses my specific problem.

I am working on a solution containing multiple libraries each of which has its own application settings file.

As long as I use the startup project, I can change the application settings by manually editing the app.config-file (e.g. "App.exe.config"). The changes made to this file are instantly reflected during runtime.

But when I try to place the settings-file from a different assembly (e.g. "Repository.dll.config") into the bin folder where the executables are stored then the settings-file is ignored.

Is there any possible way to use these settings-files as if I would use them per project?

Especially I do not want to read them by using the ConfigurationManager-class but instead I want to access them by using My.Settings

Upvotes: 0

Views: 515

Answers (1)

lc.
lc.

Reputation: 116458

If I understand you right, the settings system is not loading the file you configuration file you want it to. You can programmatically set the path for which configuration file is loaded:

AppDomain.CurrentDomain.SetData "APP_CONFIG_FILE", path_to_configuration_file

My.Settings should then work as desired. Note, I believe you can only do this before the first time the settings are accessed, that you should call the above before any attempt to access the My.Settings object.

I also believe settings will only be loaded once per application domain, so this answer may not be applicable depending on how your projects interact with each other. Someone can correct me if this is not true.

Upvotes: 1

Related Questions