'System.Configuration.ConfigurationSettings.Ap

2019-01-21 21:38发布

I got the following warning

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

How do you fix it?

12条回答
淡お忘
2楼-- · 2019-01-21 22:11

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

查看更多
smile是对你的礼貌
3楼-- · 2019-01-21 22:12

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"]; 
查看更多
再贱就再见
4楼-- · 2019-01-21 22:15

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!

查看更多
仙女界的扛把子
5楼-- · 2019-01-21 22:15

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

查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-21 22:16

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;
查看更多
Animai°情兽
7楼-- · 2019-01-21 22:20

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

查看更多
登录 后发表回答