Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

Exception in configuration section handler...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
murl - 01 Sep 2004 05:44 GMT
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...
Morten Wennevik - 01 Sep 2004 08:02 GMT
Hi murl,

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

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Murl Brown - 01 Sep 2004 08:31 GMT
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.
Morten Wennevik - 01 Sep 2004 09:03 GMT
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.

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Murl Brown - 01 Sep 2004 09:22 GMT
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...
Jakob Christensen - 01 Sep 2004 10:13 GMT
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.

> 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...
Murl Brown - 01 Sep 2004 16:31 GMT
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?
Murl Brown - 01 Sep 2004 18:31 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.