I just finished banging my head against the wall for many hours tracking down an obscure problem using OpenWebConfiguration() with custom ConfigSection‘s that use OnDeserializeUnrecognizedAttribute(). Although I’m still not sure why, the following is incorrect:

Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~/web.config");

Instead, you need to use:

Configuration configuration = WebConfigurationManager.OpenWebConfiguration( HttpContext.Current.Request.ApplicationPath);

The first one seems to work, but your ConfigurationElement loses the values of any properties set by OnDeserializeUnrecognizedAttribute(). For some reason, your constructor for your ConfigurationElement‘s get called twice.

It’s all the more frustrating because the Windows Service / Console Application version OpenExeConfiguration() worked correctly!