I know the question was posted a long time ago, but I hope this answer is still useful.
There seems to be no standard way to do this. However, gaining access to the internal fields and types of the ConfigurationManager class, I was able to list all the loaded sections. Here is how I did it:
private static IEnumerable<string> GetLoadedSections() { // s_configSystem can be null if the ConfigurationManager is not properly loaded. Accessing the AppSettings *should* do the trick. var appSettings = ConfigurationManager.AppSettings; FieldInfo s_configSystemField = typeof(ConfigurationManager).GetField("s_configSystem", BindingFlags.NonPublic | BindingFlags.Static); object s_configSystem = s_configSystemField.GetValue(null); FieldInfo _completeConfigRecordField = s_configSystem.GetType().GetField("_completeConfigRecord", BindingFlags.NonPublic | BindingFlags.Instance); object _completeConfigRecord = _completeConfigRecordField.GetValue(s_configSystem); FieldInfo _sectionRecordsField = _completeConfigRecord.GetType().GetField("_sectionRecords", BindingFlags.NonPublic | BindingFlags.Instance); Hashtable _sectionRecords = (Hashtable)_sectionRecordsField.GetValue(_completeConfigRecord); return _sectionRecords.Keys.OfType<string>(); }
The "system.diagnostics" section is always loading. The appSettings section is also loading, as I have to access it in order for it to work sequentially.
This works on my machine (.NET 4.5), but since it relies on internal things, it can be broken at any time if Microsoft decides to change the implementation of the ConfigurationManager class.
Nicolas V.
source share