Exception in configuration section handler...

  • Thread starter Thread starter murl
  • Start date Start date
M

murl

Below is what i have as the custom section in the web.config file...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<!-- register local configuration handlers -->
<configSections>
<sectionGroup name="cbsoffice">
<section name="data"
type="CbsOffice.ProviderConfigurationHandler,CbsOffice"/>
</sectionGroup>
</configSections>

*******************************************************
***Customer web.config section*************************
<cbsoffice>
<data defaultProvider="SqlDataProvider">
<providers>
<add name = "SqlDataProvider"
type = "CbsOffice.Data.SqlDataProvider,
CbsOffice.SqlDataProvider"
connectionString =
"Server=(local);Database=CbsOffice;uid=;pwd=;"
providerPath =
"..\Providers\DataProviders\SqlDataProvider\"
objectQualifier = "_"
databaseOwner = "dbo"
/>
</providers>
</data>
</cbsoffice>

The Connection handler is below...
public class ProviderConfigurationHandler :
IConfigurationSectionHandler
{
public object Create(object parent, object configContext, XmlNode
section)
{
ProviderConfiguration providerConfig=new ProviderConfiguration();
providerConfig.LoadValuesFromConfigurationXml(section);
return providerConfig;
}
}

The above function goes through the attributes of the dataprovider
section and puts them into a hashtable..however when calling the
function:
public static ProviderConfiguration GetProviderConfiguration(string
providerName)
{
return (ProviderConfiguration)ConfigurationSettings.GetConfig("cbsoffice/"+providerName);
-> equal to "cbsoffice/data"
}

It throws the Exception in configuration section, as if its not
finding the data object at all...
 
Hi murl,

Could you provide us with a little more detail?
What exactly is the error message and exception?
 
i put a catch statement around the getconfig function and recieved an
exception. Below is the code in the try/catch and the exception details:
try
{
ProviderConfiguration
providerConfig=(ProviderConfiguration)ConfigurationSettings.GetConfig("c
bsoffice/"+providerName)
}
catch (Exception ex)
{
throw ex;
}

ex.InnerException.Message = "Object reference not set to an instance of
an object." string
ex.Message = "Exception in configuration section handler.
(c:\inetpub\wwwroot\CbsOffice\web.config line 111)"string

Just to point out line 111 is the start of the <data> element as noted
earlier in the web.config file.
 
Hi Murl,

I'm in deep water here, and can't test the code, but looking at the documentations it looks like the data line should read

<section name="data"
type="CbsOffice.Configuration.ProviderConfigurationHandler,CbsOffice"

I may be very wrong though.
 
I change the section it is to getconfig from, to something thats not
even there, it will return, but nothing is there. If however i put in
the getconfig("cbsoffice/data") which is the section name that is there.
I get the configuration handler exception, explaing the object not set
to an instance. Im stumped...
 
Have you tried debugging to see if the ProviderConfigurationHandler.Create
method is called? As I put earlier, I tried your example and it works fine,
so maybe the error is thrown from your own implementation of
ProviderConfiguration?

Regards, Jakob.
 
The Create function is being called, is there anyway, that you could zip
up and send me the code you tested so i could compare and see if im
missing anything?
 
Wellllll i'll have to admit for you, that yes im a dumbass. After
debugging for over 2 hours, trying to figure this out, the _providers
Hashtable, that all the attributes were being shoved into? Was never
initialized as a new Hashtable, thats where the object refrence
exception was coming from. I correcte the problem and now it's reading
the config file fine, along with buidling the DataProvider. I won't
blame you if you guys banish me from this site forever lol...Thaks foro
your quick responses and help.
 
Back
Top