I have some code in the class library designed to target the .Net Framework 4 Client Profile. Access code for the configuration of consumer applications. For client applications (WinForms applications, console applications, etc.) Getting the right object for App.Config is very simple:
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
My class library should also work for web applications. The right way to access Web.Config is also easy:
WebConfigurationManager.OpenWebConfiguration("~");
The problem is that the WebConfigurationManager is part of System.Web, which is not available as part of the .Net Framework 4 Client Profile.
Is there a way to write my code or the structure of my project so that it works in both cases? It should work well enough to access app.config on systems where only the client profile is installed. It should also have access to web.config if necessary. Perhaps there is a way that I can dynamically load system.web or another assembly when it is available and when it is needed?
source share