Is there a simple way to read from the global application.exe.config file from a dll?
Currently I am loading the file as an XmlDocument but I wonder if there is a better solution.
That’s what I mean:
- If I create a new WinForms Project I have a Settings Tab in the Project properties where I can add some simple values (And I want to access the per Application settings, not the user beased ones).
-
From my code I can access these values with:
Console.WriteLine(Properties.Settings.Default.SomeValue);
The Settings class is autogenerated in the file Settings.Designer.cs.
Now I have the case where a dll need’s to read the settings from the Main Application’s config file. Is there a simple way to achive this? Currently I am reading the file as an XML Document.
If you implement an
ApplicationSettingsBasein your DLL, it will actually read the application.exe.config anyway – you just need to add the relevant config sections to it. The .dll.config file output by the compiler is generally a useless piece of crap, because the DLL won’t even look at it.The easiest way to get what you want is to add yourself a settings file to the DLL and use it within the DLL – when the app.config is generated, copy those sections over to the app.config file in the executable. (Unfortunately this isn’t automated, it should be).