Reputation: 874
I have a command line utility app designed for making server backups. I've also got a GUI app that gives access to various maintenance functions, including the ability to make server backups. Previously, this app duplicated the backup code, which was causing consistency and maintainability issues. I'm in the process of refactoring the GUI app to reference the command line app and call its backup methods instead, in the name of code reuse.
I've just run into a problem, though - the command line app has a config file, read using ConfigurationManager.AppSettings
. When it's called directly, that works fine. When it's called as a reference from the GUI app, though, it tries to read the GUI app's config file instead, as the executing assembly, and throws an error when it can't find the values it expects.
How can I force the code to always read the command line app's config file, even when it's not actually the executing assembly?
Upvotes: 0
Views: 256
Reputation: 160
Just set AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
Upvotes: 1