locked
System.Configuration.ConfigurationManager.AppSettings Does Not Exist

    Question

  • I am trying to upgrade a VB 2003 program to VB 2005. 

    One warning I am getting is:

    'Public Shared ReadOnly Property AppSettings() As System.Collections.Specialized.NameValueCollection' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings' C:\CS\CSolution\bin\Classes\Utilities.vb 8380 25 CSolution

    1) what does the ! mean in the terminology of "System.Configuration!" above?

    2) More importantly, in "System.Configuration.ConfigurationManager.AppSettings" I cannot get ConfigurationManager to show up as an option in intelesense.  It shows as an error if I try to use it anyway.

    3) I have searched help, and for the life of me, I cannot figure out how to read a simple app.config file value. 

    Please advise.

    Thanks!

    bob

    Thursday, October 05, 2006 6:10 PM

Answers

  • Add a reference to System.Configuration.dll, and you should be able to use the System.Configuration.ConfigurationManager.

    Depending on what you want kind of settings you want for your application, I would recommend that you check out the new Settings designer in Visual Studio 2005. For more info, check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/vbmysettings.asp

    Best regards,
    Johan Stenberg

     

    Thursday, October 05, 2006 10:02 PM
  •  BobInIndy wrote:

    1) what does the ! mean in the terminology of "System.Configuration!" above?

    It's shorthand for specifying the DLL and the fully qualified class/property.  The form is 'assemblyname!property/class/field'.  So this indicates the System.Configuration dll.

     BobInIndy wrote:

    2) More importantly, in "System.Configuration.ConfigurationManager.AppSettings" I cannot get ConfigurationManager to show up as an option in intelesense.  It shows as an error if I try to use it anyway.

    Can you post a code snippet detailing this problem? 

     BobInIndy wrote:

    3) I have searched help, and for the life of me, I cannot figure out how to read a simple app.config file value. 

    Reading app.config is a pretty big subject.  Can you be more specific on what type of data you want to read out of app.config?

    Thursday, October 05, 2006 9:19 PM

All replies

  •  BobInIndy wrote:

    1) what does the ! mean in the terminology of "System.Configuration!" above?

    It's shorthand for specifying the DLL and the fully qualified class/property.  The form is 'assemblyname!property/class/field'.  So this indicates the System.Configuration dll.

     BobInIndy wrote:

    2) More importantly, in "System.Configuration.ConfigurationManager.AppSettings" I cannot get ConfigurationManager to show up as an option in intelesense.  It shows as an error if I try to use it anyway.

    Can you post a code snippet detailing this problem? 

     BobInIndy wrote:

    3) I have searched help, and for the life of me, I cannot figure out how to read a simple app.config file value. 

    Reading app.config is a pretty big subject.  Can you be more specific on what type of data you want to read out of app.config?

    Thursday, October 05, 2006 9:19 PM
  • Add a reference to System.Configuration.dll, and you should be able to use the System.Configuration.ConfigurationManager.

    Depending on what you want kind of settings you want for your application, I would recommend that you check out the new Settings designer in Visual Studio 2005. For more info, check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/vbmysettings.asp

    Best regards,
    Johan Stenberg

     

    Thursday, October 05, 2006 10:02 PM
  • Not sure if you're still searching, but I found this

    <<You can reference this directly from code using:

    [C#]
    string connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;

    [VB]
    Dim connStr As String = ConfigurationManager.ConnectionStrings("MainConnStr").ConnectionString

    Note that the namespace for this is System.Configuration so for a console application the full namespace is required.>>

    on this:

    http://weblogs.asp.net/owscott/archive/2005/08/26/Using-connection-strings-from-web.config-in-ASP.NET-v2.0.aspx

    Friday, February 16, 2007 1:08 AM
  • Have to agree with Bob. I was using

    system.Configuration.ConfigurationSettings.AppSettings("Version") and it now flags it as Obsolete (even though it worked fine in Debug within the Immediate window).

    I tried strTemp = system.Configuration.ConfigurationManager.AppSettings("Version")

    but it flags it as  'ConfigurationManager' is not a member of 'Configuration'

    I have included an   Imports System.Configuration  statement at the front as well. This really is poor. It shouldn't be so difficult to replace the one statement (that worked) with this new one that doesn't. C'mon Microsoft get your act together. Do you think we've all day to mess with these stupid error messages and their lack of correct guidance?

    rosecalf@hotmail.co.uk

     

     

    Tuesday, February 27, 2007 1:04 PM
  • Please note that there is a big difference between importing a namespace (putting an Imports <whatever namespace> in your file) and adding a reference to an assembly - the Import simply lets you refer to types without having to specify the fully namespace qualified type name *if you have a reference to the assembly where the type is defined*.

    Adding a reference actually makes the type available to the referencing assembly (in your case, the application)

    There is not a one-to-one mapping between namespace and assembly, so you can't determine which assembly a type is defined in by looking at the namespace.

    Best regards,
    Johan Stenberg

    Tuesday, February 27, 2007 6:13 PM
  • I have tried adding a project reference to System.configuration.dll and using the fully qualified class name:

    System.Configuration.ConfigurationManager.AppSettings.Item("ReportServer")

    but I get the same compile error, indicating that ConfigurationManager is not a member of Configuration.  What is even more perplexing is that I have the exact same line of code in another website and it works just fine.  I have even tried removing and adding the project reference again, to no avail. 

    Thoughts, anyone?

    Jim S.

    Tuesday, March 13, 2007 8:21 PM
  • You need to right click your References and add a reference to System.Configuration before you are able to use ConfigurationManager.  For some reason, some System.Configuration options are available without this, but not all.
    Friday, March 16, 2007 9:33 AM
  • The normal procedure, adding a reference to the assembly and using the fully qualified name, worked after a reboot.  I am not sure why it needed one, but it did.

    The reason why System.Configuration seems to work sometimes and not others is because there are the old System.Configuration namespace and the new System.Configuration assembly have the same name.  Just reference the .dll and refer to it in the manner noted throughout this thread:

    System.Configuration.ConfigurationManager.AppSettings.Item("ItemName")

    Friday, March 16, 2007 9:36 PM
  • Just add System.Configuration as a reference to the project and also include using system.configuration.

     

    this should fix the problem.

     

    Monday, April 07, 2008 5:35 AM
  • 1) Right click your project.
    2) Select "Properties"
    3) Click References
    4) Click "Add"
    5) Select System.Configuration
    6) Click "Ok" then save the configuration
    7) Go to www.RichmondOut.com
    • Proposed as answer by NZCoder Wednesday, October 13, 2010 7:56 PM
    Tuesday, May 13, 2008 2:13 AM
  • This was it for me.

    Thanks for putting up with us newbies.







    Please note that there is a big difference between importing a namespace (putting an Imports <whatever namespace> in your file) and adding a reference to an assembly - the Import simply lets you refer to types without having to specify the fully namespace qualified type name *if you have a reference to the assembly where the type is defined*.

    Adding a reference actually makes the type available to the referencing assembly (in your case, the application)

    There is not a one-to-one mapping between namespace and assembly, so you can't determine which assembly a type is defined in by looking at the namespace.

    Best regards,
    Johan Stenberg


    Monday, May 19, 2008 6:00 PM
  • Hi  Johan,

    Thanks for the post :

    Helped me to Add Reference of System.Configuration to get ConfigurationManager

    Thanks

    Cheers

    Karthik
    Thursday, September 25, 2008 10:31 AM
  • Hi  Johan,

    Thanks for the post :

    Helped me to Add Reference of System.Configuration to get ConfigurationManager

    Thanks

    Cheers

    Karthik
    Thursday, September 25, 2008 10:31 AM
  • Hi  Johan,

    Thanks for the post :

    Helped me to Add Reference of System.Configuration to get ConfigurationManager

    Thanks

    Cheers

    Karthik
    Thursday, September 25, 2008 10:31 AM
  • Thanks Bob, I finally understand this ! as well. Humm, your post is still useful after 3 years! -Eric
    Friday, May 29, 2009 3:25 PM
  • heyyy johan i am working on windows application and am trying to find  System.Configuration.ConfigurationManager

    but i can't find it  plz help

    Mina Jeffrey
    Wednesday, January 27, 2010 12:24 PM
  • heyyy johan i am working on windows application and am trying to find  System.Configuration.ConfigurationManager

    but i can't find it  plz help

    Mina Jeffrey
    Wednesday, January 27, 2010 12:26 PM
  • Just my 2 cents but I'm using Visual Studio 2010 and the correct reference is still not added by default.

    As another questioner wrote - Come on Microsoft - Get it together!

    If it's depreicated at lest save us the time of trying to figure out how to use it by adding the correct reference and removing the old one.

    Saturday, May 01, 2010 3:00 PM
  • IMHO,

    Changing base functionality like this is aggravating to developers and support personnel.  Sure, we can add references to System.Configuration if you need us to.  I would think almost every application out there needs configuration so why do we need to manually add a reference, expecially when I use your tools to add an App.Config file?

    It would be nice to see a page to explain why this was changed.  Believe it or not this simple change just cost companies thousands of hours of development time for what reason?   Where is your change control and justification? 

    Concerned Developer who now has more job security!

     

    Tuesday, July 06, 2010 4:56 PM
  • Just my 2 cents but I'm using Visual Studio 2010 and the correct reference is still not added by default.

    As another questioner wrote - Come on Microsoft - Get it together!

    If it's depreicated at lest save us the time of trying to figure out how to use it by adding the correct reference and removing the old one.



    Microsoft Visual Studio
    Wednesday, July 07, 2010 7:41 AM
  • Thanks Dudeman for writing steps. It helped me for adding reference

     

    Regards

    Eqirtas

     

    Tuesday, August 17, 2010 7:53 AM
  • trying out VS 2010 and seeing the same problem too. thanks Dudeman
    Friday, August 27, 2010 11:16 PM
  • Poor VS 2010  !! this cost my 2 hours time . not happy .
    Saturday, August 28, 2010 5:06 AM
  • So what is the solution for VS2010? I've tried adding the reference and I'm still getting :

    'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'

    Figured it out, just had to change my code to actually use the line (ConfigurationManager):

     

     

     

    ConfigurationManager.AppSettings["IShoppingDataAccessType"];

     

     

    Type t = Type.GetType(typeName);

     

    string typeName =

     

     

    Friday, September 24, 2010 9:30 AM
  •  

     BobInIndy wrote:

     

    1) what does the ! mean in the terminology of "System.Configuration!" above?

     

     

    It's shorthand for specifying the DLL and the fully qualified class/property.  The form is 'assemblyname!property/class/field'.  So this indicates the System.Configuration dll.

    How can anyone (in the know) keep a straight face after an answer like that?  I bet right after you posted this you busted up laughing, hyucking it up at the expense of people who take things literally.  I am a sentient life form.  I have a brain.  I read the error that Microsoft generates and I scratch my head looking for hours for the strange .DLL with an exclamation point in the freakin name!  Can't find all day.  I spent hours and hours on this issue.  And you respond back with a short curt response "It's shorthand for..."  SHORTHAND?  So IIWWIOMMWYUT?  That's shorthand for what I was thinking.  Can you guess what it says?

    All you Microsoft clowns are ejected out of the same freaking molds.  Take that back to your leader.  And after he hyuck hyuck hyuck's it up, laughing for the mere sake of laughing at the people who didn't quite understand your codified terminology, then kindly take this freaking baseball bat and give him a heavy whack in the back of the head for me, okay.

     

    Monday, October 04, 2010 9:14 PM
  • If you are using visual studio 2010 and still running into this problem here you go.

    No need to import or add a reference.

     

    Web.config

    <appSettings>
            <add key="ServiceKey" value="000001"/>
       </appSettings>

    VB Code behind

    Dim pin = System.Configuration.ConfigurationManager.AppSettings.Item("ServiceKey")

    • Proposed as answer by ponka nemov Friday, May 27, 2011 5:05 PM
    Sunday, January 02, 2011 1:35 AM
  • nice post.... thanks for the solution...

     

    Regards,

    Ali Raza

    http://techgulf.blogspot.com/

    Saturday, January 08, 2011 4:23 AM
  • Hi everyone,

    I experienced the same problems as you guys. I just installed VS2010... took me a while to find out the problem. It says that it can find System.Configuration.C... etc. The reason here is the "configuration" in the dll file is in lower case.... -_-.. I don't know for you but I just changed the dll to System.Configuration.dll and now VS2010 can now actually identify ConfigurationManager...

    This is disappointing...

    Monday, April 18, 2011 4:03 PM
  • Hi everyone,

    I am experiencing the same problem too, though one step behind you all. I can not even add "System.Configuration". When I try to add it, i select "System.Configuration" in the .NET tab ; at least this is what is displayed on screen, visual problem maybe ?!!, but VS 2010 keeps placing the one called "System.configuration".

    I have already spend hours on that, trying to figure out what the problem is.

    Can any one advise ? Is it also possible to have a small example.

     

     

     

    Friday, May 20, 2011 11:18 AM
  • AS DaveCS posted for VS 2010..did work for me too. No additional references needes or else.. just only write as he posted.
    Friday, May 27, 2011 5:06 PM
  • check DaveCS solution. IT works
    Friday, May 27, 2011 5:09 PM
  • That did the trick - thanks.
    Wednesday, June 15, 2011 8:52 AM
  • Add Reference of System.Configration from Right Click of project...then u Can Access Of AppSetting Of WebConfig file...
    Thursday, November 24, 2011 9:25 AM
  • That really worked. :)

    Friday, March 09, 2012 10:13 AM
  • I would if that were possible.

    In Visual Studio 2012 Lightswitch there is no option to add System.Configuration.dll

    There are a lot of references that should be there that are not. System.Web is missing as well.

    Friday, October 12, 2012 3:23 PM
  • Thank you so much for this tip. Lousy microsoft cost me a night of progress trying to figure this out.
    Sunday, October 21, 2012 4:03 AM
  • Which project are you trying to add a reference to System.Configuration to? Since there is no System.Configuration.dll in Silverlight, you wouldn't be able to add it to the client project. The same with the common project, since that is, under the hood, a silverlight assembly that can run on both the client and the server.

    For the server project, I have just verified that it is available (at least on my machine :)).

    Best regards,
    Johan Stenberg


    Development Lead, Visual Studio LightSwitch

    Monday, November 19, 2012 10:40 PM
  • This happens because you're working with an upgraded project!

    The newer versions of MS Visual Studio use a different way to storage the settings, by creating a user or global strongly typed constant  for each setting. Just correct each line this way:

    E.g.

               //val = ConfigurationSettings.AppSettings["MyDefaultSetting"];
                val = MyDefaultSetting;

    Friday, November 30, 2012 10:11 PM
  • Hi Johan

    I am trying to create a dll  in VB.NET with VS2010 which will help me to connect to a database.

    But unfortunately I tried each solutions proposed by this page by everyone but nothing. I install the update1 maybe I will get the ConfigurationManager or the Webconfiguration Class.

    Please help.

    Thank you

    Best regards

    Tuesday, December 04, 2012 11:56 AM