'System.Configuration.ConfigurationSettings.AppSettings' is obsolete

前端 未结 12 1848
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 03:22

I got the following warning

\'System.Configuration.ConfigurationSettings.AppSettings\' is obsolete: \'\"This method is obsolete, it has been replace

相关标签:
12条回答
  • 2020-12-13 04:14

    Just in case someone else was looking for the Add Reference option to achieve the accepted answer in Visual Studio 2010. (I had to do this in updating a VB project).

    In Visual Studio 2010:

    1. Click on Project > Add Reference.
    2. Click on the C# tab (even though mine was a pure VB project)
    3. Scroll down halfway to find System.Configuration (I had v4 since .NET Framework 4.0 was the chosen version)
    4. Click OK, then update the line of code as per the suggestion given.

    From System.Configuration.ConfigurationSettings.AppSettings("name") to System.Configuration.ConfigurationManager.AppSettings

    Without adding the reference IntelliSense won't suggest ConfigurationManager when you type it, and that's because it doesn't have a reference to be aware of where it is. Which is also why you will get errors when you updated the line of code according to their suggestion.

    0 讨论(0)
  • 2020-12-13 04:14

    the System.configuration DLL exsit in c:\Windows\Microsoft.NET\Framework\v2.0.50727\

    0 讨论(0)
  • 2020-12-13 04:17

    to use ConfigurationManager.AppSettings[""] Add Reference Assemblies not use using System.Configuration;

    0 讨论(0)
  • 2020-12-13 04:17

    It's simple as mentioned above, just add a reference "System.Configuration" for the application, and within the code you can add "using System.Configuration" to the top of the code and use "ConfigurationManager.AppSettings[""]" where you need it.

    0 讨论(0)
  • 2020-12-13 04:18

    After adding the reference using System.Configuration; at the top of the class. Still the same warning remains.

    In Code Behind:

    Instead of ConfigurationSettings.AppSettings["ConnectionString"]

    Use ConfigurationManager.AppSettings["ConnectionString"]

    By Default the System.configuration Dll will be added in your project.

    In Web.config or App.config:

     <add key="ConnectionString" value="Some Connection Strings or Specific Path"/>
    
    0 讨论(0)
  • 2020-12-13 04:22

    you must add reference of System.onfiguration in your project then add "Using System.onfiguration;"

    next step using like this:

    private string SQLConnectionString = ConfigurationManager.AppSettings["SQlConnectionString"]; 
    
    0 讨论(0)
提交回复
热议问题