'ConfigurationManager.GetSection' is not backwards compatible for nested sections
julealgon opened this issue · 0 comments
julealgon commented
After migrating from System.Configuration
's ConfigurationManager
into AnyConfig
's, I started to get errors related to nested XML sections that were previously working with the legacy class.
Here is an example:
var customErrors = (CustomErrorsSection)ConfigurationManager.GetSection("system.web/customErrors")
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" maxQueryStringLength="32768" maxUrlLength="65536" maxRequestLength="524288000" enableVersionHeader="false" />
<customErrors mode="Off" />
<globalization culture="auto:en-US" uiCulture="en" />
</system.web>
Notice how we are fetching the customErrors
section inside system.web
. The call works as expected when using the legacy class, but returns null
using AnyConfig
's implementation.
If I change the code to read only the "system.web"
section, it fetches the main section correctly.
I believe this is a gap in the backwards compatibility of the ConfigurationManager
class.