Reputation: 496
I have two projects in a solution; one is a dll-project and the other is a web API. Both .NET Core.
When I test the dll, or compile it and run as a console app the configuration works just fine. When I reference it from the web API, everything builds and the resulting .dll.config is placed in the correct place. Looking at AppDomain.CurrentDomain.SetupInformation.ApplicationBase
gives me the expected path.
However, when I run the web API in debug and hit a breakpoint in the referenced project, none of the expected settings are found in ConfigurationManager.Appsettings.
Is there something I have overlooked, or do I need to specify the configfile for ConfigurationManager when using it as a DLL?
Upvotes: 0
Views: 1915
Reputation: 4461
When you retrieve a Configuration object using the "normal" method, the object you get back is tied to the configuration of the App Domain you are executing in, rather than the particular assembly.
See this answer for more detailed information.
But in short, ConfigurationManager.Appsettings
always read config file of main application, but still you can read dll configs this way:
var config = ConfigurationManager.OpenExeConfiguration("foo.dll");
Upvotes: 2