views:

651

answers:

1

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.

+3  A: 

How about switching the slash direction:

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

Here's a similar example from MSDN.

Robin M
this is the answer...!!
Krunal
That certainly did something. But now the cast fails. D'oh! ansd that's because I'm trying to use an existing section, which has already got a type defined (system.Configuration.SingleTagSectionHandler) with my own ConfigurationSection derived class.