troubleshooting Question

C# ConfigurationManager.GetSection returns null

Avatar of CipherIS
CipherISFlag for United States of America asked on
C#Visual Basic.NET.NET Programming
4 Comments1 Solution6995 ViewsLast Modified:
I am trying to get the section in my app.config file.  I'm using ConfigurationManager.GetSection but always get a null value.  Below is my code and app.config file.

Any ideas?

NameValueCollection nvc = (NameValueCollection)ConfigurationManager.GetSection("groupInfo/sectionInfo1");
if (nvc != null)
{
    for (int i = 0; i < nvc.Count; i++)
    {
        Console.WriteLine(nvc[i] + " = " + nvc.Keys[i]);
     }
}

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

    <configSections>
        <sectionGroup name="groupInfo">
            <section name="sectionInfo1" type="System.Configuration.NameValueSectionHandler"/>
            <section name="sectionInfo2" type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
    </configSections>

    <groupInfo>
        <sectionInfo1>
            <add key="myKeyA" value="AAA"/>
            <add key="myKeyB" value="BBB"/>
        </sectionInfo1>
    </groupInfo>
        
</configuration>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros