Thursday, June 19, 2008

Couldn’t find ConfigurationManager in System.Configuration?

I am trying to pull an appSettings key from my web.config. In .NET 1.1, we usually use:

System.Configuration.ConfigurationSettings.AppSettings["strConnection"].ToString();

However, in .NET2.0, using this code will cause the following error:

'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'
So I just change my code to the following, according to the error above. But the problem is I can’t find ConfigurationManager in the System.Configuration.

The reason is because the original System.Configuration.ConfigurationSettings class is point to the System.dll assembly. There is another new the System.Configuration.dll assembly with the new ConfigurationManager class. In this case, you need to add in the System.Configuration.dll as a reference to your application before you can use it.

Hope this will help someone.

3 comments:

Zac Kloepping on October 15, 2008 at 10:14 PM said...

Just helped me, thanks!

I had just converted a project from .net 1.1 to 2.0 and was having the same issue.

Nelson Rocha on January 29, 2009 at 9:39 AM said...

Thanks a lot!

You sure hit the point here.
For some reason my VS 2008 didn't load the updated assembly and I was freaking out with some imported projects.

Justin on April 9, 2009 at 5:18 AM said...

Just helped me :) thanks

 

Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
Sign up for PayPal and start accepting credit card payments instantly. http://www.emailcashpro.com
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template