'System.Configuration.ConfigurationSettings.AppSettings' is obsolete

前端 未结 12 1847
被撕碎了的回忆
被撕碎了的回忆 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 03:58

    as its a warning i dont think it matters unless you have turned off a treat warnings as errors setting

    add a reference to System.Configuration

    all you have to do is to update to the latest code so where you used ConfigurationSettings.AppSettings[""] change to ConfigurationManager.AppSettings[""]

    and this should work

    0 讨论(0)
  • 2020-12-13 03:59

    I had the same problem in a C# project and I fixed it by writing appSettings instead of AppSettings in the XML file (camelCase expected) in the tag

    <appSettings>
      <add key="myKey" value="my Value"/>
    <appSettings>
    

    After all C# is case sensitive

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

    Just replace
    System.Configuration.ConfigurationSettings.AppSettings
    with
    System.Configuration!System.Configuration.ConfigurationManager.AppSettings
    in your code.

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

    I also face same issue, sometimes the assembly reference not loaded properly or if you are using multiple projects it give problems sometimes. You just add reference to assembly. Right Click>Add Reference>.Net>System.configuration> Click OK You can see now there are many configuration options available choose ConfigurationManager.AppSetting["Con"].ToString();

    Build and Smile :)

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

    Add a reference to the assembly System.Configuration.

    Then at the top (assuming C#) using System.Configuration (Imports System.Configuration in VB.NET).

    Use ConfigurationManager.AppSettings["MySetting"] to access the settings!

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

    example:

    replace

    string smtpServer = System.Configuration.ConfigurationSettings.AppSettings["EmailServer"];
    

    with

    string smtpServer = ConfigurationManager.AppSettings["EmailServer"];
    

    also make sure on the top of the case you add:

    using System.Configuration;
    
    0 讨论(0)
提交回复
热议问题