I have a class library(abc.dll) in which i have used a settings file. An exe (app.exe) references this class library. At runtime if i want to change the values of the settings without having to rebuild the class library/application, what is the best way to approach this problem ? In my current approach the setting values get embeded in the library, and thus i dont see any way to update them without rebuilding the whole thing.
A:
One mechanism involves setting up a configuration file to contain the required information.
Basically, you're looking for the modern equivalent of the old Win16/Win32 .INI files.
.NET supports .config files for this purpose (see the .NET documentation for this).
In my own projects, I've used a mix of .config files and my own XML files. The choice would be up to you.
The tradeoff here is that your application/classlib becomes more complex to support the initialization. The advantage is that if done correctly, you can accomplish significant changes to app/library behavior without requiring a recompile.
kmontgom
2010-04-19 14:28:31
You can do this by adding an app.config file to your project in Visual Studio. Watch out though: app.config files for DLL assemblies must be manually loaded.
Damian Powell
2010-04-19 15:32:31
Interesting. For some strange reason, I'm not a particular fan of the .config approach. I probably should be, but I like making my own XML config layout.Are there any additional "gotchas" with the .config mechanism?Are there any strong reasons to prefer .config over roll-your-own config?
kmontgom
2010-04-19 16:01:40
Manually loading the config as xml and processing it would have been an overkill for my current purpose. So I have fallen back to using the exe's config file.
mishal153
2010-04-22 05:19:25