关于appSettings

时间:2016-05-16 12:34:20

标签: vb.net

我到处搜索如何摆脱这个警告,没有运气。我添加了对Module1.vb的引用:Imports System.Configuration并且我尝试过: Imports System.Configuration.ConfigurationSettings。仍然没有运气。

这是我的代码:

Dim sAttr As String
sAttr = ConfigurationSettings.AppSettings("TITLE")

Console.WriteLine("The value of TITLE is: " & sAttr)
Console.ReadLine()

这是我的配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TITLE" value="Mr"/>
</appSettings>
</configuration>

我收到警告:

ConfigurationSettings.AppSettings("TITLE")

就像我说的那样。我已经用Google搜索了这个警告,我遇到的唯一调查结果是我需要添加对System.Configuration的引用,我已经尝试了,我仍然有警告。我还发现我需要添加对System.Configuration.dll的引用,但这个语句是不必要的,并给我一个警告。

任何帮助将不胜感激!谢谢!

编辑:好的,我弄明白为什么我会收到警告。我把引用放在错误的项目中。 (傻我)但是现在,当我想看到标题的价值时,什么也没有显示出来。在控制台中应该是这样的:

The value of TITLE is: Mr

任何人都知道为什么价值或钥匙没有显示?再次感谢! :)

1 个答案:

答案 0 :(得分:0)

要修复此警告,而不是使用ConfigurationSettings.AppSettings,您需要将其更改为ConfigurationManager.AppSettings,因为ConfigurationSettings不再使用。