C# – ConfigurationManager – How to use connection strings with .NET 3.5

cconfigurationconnection-stringnet

I see a very good post here about what I am wanting to do,

.net 3.5: To read connectionstring from app.config?

It says to use the ConfigurationManager class. I cannot reference the ConfigurationManager class.

If I look at the system.dll that I am using (which is v2.0.50727) there is no ConfigurationManager class.

I am using VS 2008, and my project is set to compile as .NET 3.5.

If I do this,

string test = System.Configuration.ConfigurationManager.AppSettings["test"];

I get the message 'Error 182 The type or namespace name 'ConfigurationManager' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?)'

Any ideas?

Best Answer

The ConfigurationManager is part of the System.Configuration namespace. By default it is not referenced in the projects, so add a reference to if from the GAC.