Error trying to read Custom Configuration Sections

G

Guest

Dear all,
I have created personalized configuration sections in my web project
following the instructions described in this page
http://msdn.microsoft.com/library/d...cpconDeclaringCustomConfigurationSections.asp

The problem is that I using the same code and I get the error "Object
reference not set to an instance of an object" in the line where I try to
read the first parameter (in the page attached : value1 =
CType(sampleTable("setting1"), String)).

I have made some investigations and this error occurs when you don't create
the object with new. The problem is that in this case is not possible because
IDictionary is an interfaz.

I have also investigated that it could be a version problem, here you can
find the versions I'm using Microsoft .NET Framework, Version:1.1.4322.573
ASP.NET Version:1.1.4322.573

can you help me?

Thank you very much.

Regards,
Paloma García.
 
K

Kevin Spencer

The problem is that I using the same code and I get the error "Object
reference not set to an instance of an object" in the line where I try to
read the first parameter (in the page attached : value1 =
CType(sampleTable("setting1"), String)).

Did you create a custom Configuration Section in your web.config or
app.config file? Did you create it as a SingleTagSectionHandler type? Did
you declare it correctly in the <configSections> section of the config file?
Did you put the actual section into the config file, in the proper location?
Did you instantiate the IDictionary, as per the sample, using the static
ConfigurationSettings.GetConfig() method prior to trying to get data out of
it?
I have made some investigations and this error occurs when you don't
create
the object with new. The problem is that in this case is not possible
because
IDictionary is an interfaz.

Create WHAT object? The object that you have cast as an IDictionary is
returned by the ConfigurationSettings.GetConfig() method. You are simply
casting it as an IDictionary type (that is, a class that implements
IDictionary). When you create a custom Section of type
SingleTagSectionHandler, it creates an object of type IDictionary. You can
get an instance of the object without using the New operator. You can get an
instance of an object as the return value of a function (such as
ConfigurationSettings.GetConfig()). The only reason that such a function
would return Nothing is if an exception occurred in the function, or
possibly in this case, if the function didn't find what you told it to find.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.
 

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top