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:

  1. Just helped me, thanks!

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

    ReplyDelete
  2. 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.

    ReplyDelete