Visual Basic > Visual Basic Forums > Visual Basic Language > System.Configuration.ConfigurationManager.AppSettings Does Not Exist
Ask a questionAsk a question
 

AnswerSystem.Configuration.ConfigurationManager.AppSettings Does Not Exist

  • Thursday, October 05, 2006 6:10 PMBobInIndy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

Answers

  • Thursday, October 05, 2006 10:02 PMMSFT Johan StenbergModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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 9:19 PMJared Parsons MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     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?

All Replies

  • Thursday, October 05, 2006 9:19 PMJared Parsons MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     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 10:02 PMMSFT Johan StenbergModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

     

  • Friday, February 16, 2007 1:08 AMDaranee Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Tuesday, February 27, 2007 1:04 PMvigorniensis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 6:13 PMMSFT Johan StenbergModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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, March 13, 2007 8:21 PMnonyabiz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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.

  • Friday, March 16, 2007 9:33 AMwaden34 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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:36 PMnonyabiz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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")

  • Monday, April 07, 2008 5:35 AMkrishGuru Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Just add System.Configuration as a reference to the project and also include using system.configuration.

     

    this should fix the problem.

     

  • Tuesday, May 13, 2008 2:13 AMDudeman 3000 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Monday, May 19, 2008 6:00 PMLarryEisenstein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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


  • Thursday, September 25, 2008 10:31 AMVirtual Connections Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 AMVirtual Connections Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 AMVirtual Connections Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi  Johan,

    Thanks for the post :

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

    Thanks

    Cheers

    Karthik
  • Friday, May 29, 2009 3:25 PMEricV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks Bob, I finally understand this ! as well. Humm, your post is still useful after 3 years! -Eric