Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationManager.GetSection returning null for appparently correct 'path'

This is regarding a web.config file

Here's the ConfigSection

<configSections>
<sectionGroup name="HttpExceptionHandler">
  <section name="errorLog" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <section name="errorMail" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>

Here's the SectionGroup:

<HttpExceptionHandler>
    <errorLog type="MI.Generic.HttpExceptionHandler.SqlErrorLog, MI.Generic.HttpExceptionHandler" dataSource="opentraderdev\dev" initialCatalog="MiTraderError" />
</HttpExceptionHandler>

Here's the code:

public class ErrorLogConfiguration : ConfigurationSection
{
    public static ErrorLogConfiguration GetConfig()
    {
        return ConfigurationManager.GetSection("HttpExceptionHandler\\errorLog") as ErrorLogConfiguration;
    }

    [ConfigurationProperty("initialCatalog", IsRequired = true)]
    public string InitialCatalog
    {
        get
        {
            return this["initialCatalog"] as string;
        }
    }

    [ConfigurationProperty("dataSource", IsRequired = true)]
    public string DataSource
    {
        get
        {
            return this["dataSource"] as string;
        }
    }
}

The return is always null. I've run out of ideas. Any help appreciated.

like image 752
user129345 Avatar asked Feb 27 '23 21:02

user129345


1 Answers

How about switching the slash direction:

return ConfigurationManager.GetSection("HttpExceptionHandler/errorLog") as ErrorLogConfiguration;

Here's a similar example from MSDN.

like image 88
Robin Minto Avatar answered May 01 '23 15:05

Robin Minto