Exception in configuration section handler...

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...
 
M

Morten Wennevik

Hi murl,

Could you provide us with a little more detail?
What exactly is the error message and exception?
 
M

Murl Brown

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.
 
M

Morten Wennevik

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.
 
M

Murl Brown

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...
 
G

Guest

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.
 
M

Murl Brown

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?
 
M

Murl Brown

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top