Reputation: 1117
I have a command line application that reads some settings from the app.config file, using the usual Properties.Settings.blabla
properties.
This application is also used as a dll.
When I use it as a dll, it ignores any foo.exe.config that I drop in the directory. It doesn't throw an exception as I expected when using the methods that access the config file, but it doesn't take the config file either.
Is there a way to have an exe that is being used as a dll consume its own settings file, and still have it use the app.config file when used an an exe? I don't want to change neither the consumer code, and I want as little impact as possible on the exe code.
I've seen solutions using ConfigurationManager.OpenMappedExeConfiguration
Method or OpenExeConfiguration
, is the solution using those methods inside the exe code? That way it will always look for the config file, regardless of if it is being used as dll or exe?
Upvotes: 1
Views: 987
Reputation: 40160
If you want to do that, you'll need to read specifically from that file. A .NET executable reads from it's own app.config
file. Library code always reads from the app.config
file for the application being executed... even library code that just happens to have been compiled into a file with an .exe extension.
Edit for Emphasis/Clarification
When I speak of an app.config
, I am of course talking about the appropriately-renamed [program.exe.config]
file.
Upvotes: 2