ConfigurationManager problems

AstroGuy
AstroGuy used Ask the Experts™
on
I keep getting the following error message no matter what I try
The name 'ConfigurationManager' does not exist in the current context
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Configuration;
//using System.Configuration.Assemblies;
 
namespace C9_1AllAppSettings490
{
    class Program
    {
        static void Main(string[] args)
        {
            NameValueCollection AllAppSettings = ConfigurationManager.AppSettings; 
            Int32 Counter = 0;
            IEnumerator SettingsEnumerator = AllAppSettings.Keys.GetEnumerator(); 
            while (SettingsEnumerator.MoveNext())
            {
                Console.WriteLine("Item: {0}   Value: {1}", AllAppSettings.Keys[Counter], AllAppSettings[Counter]);
            } 
 
        }
    }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Add reference to assembly System.Configuration.

System.Configuration.dll refrence is missing.


Author

Commented:
jinal,
"using System.Configuration;" is plainly visible in the code above.  /the system will not accept
using System.Configuration.dll
What are you refering to ??;

Richard LeeSoftware Enthusiast

Commented:
Namespaces can span across assemblies - although you can include this namespace without any errors the class ConfigurationManager / some of its members (possible due to partial classes) are not available until you reference the assembly System.Configuration.dll.

As stated by Jinal you need to add a reference  to System.Configuration.dll and then the System.Configuration.ConfigurationManager will become available.

Adding and assembly reference and using a namespace are two different things.

http://msdn.microsoft.com/en-us/library/wkze6zky(VS.80).aspx
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Author

Commented:
The code you see is all the code there is.

When I add using System.Configuration.dll.I get and error.
I don't understand.
Commented:
Hello  ,

i am not telling that you haveo add this to using System.Configuration.dll at top.

It should be like this only ( Attached Code ) .

But you have to add refrence. (Please see attached image)

Go to project menu > Add reference

Then choose System.Configuration from Add reference window.

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Configuration;
 
 
namespace C9_1AllAppSettings490
{
    class Program
    {
        static void Main(string[] args)
        {
            NameValueCollection AllAppSettings = ConfigurationManager.AppSettings; 
            Int32 Counter = 0;
            IEnumerator SettingsEnumerator = AllAppSettings.Keys.GetEnumerator(); 
            while (SettingsEnumerator.MoveNext())
            {
                Console.WriteLine("Item: {0}   Value: {1}", AllAppSettings.Keys[Counter], AllAppSettings[Counter]);
            } 
 
        }
    }
}

Open in new window

1.JPG
2.JPG

Author

Commented:
Sorry Jinal that it took so long to get back to you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial