' System.Configuration.ConfigurationManager.AppSettings'语言不支持

时间:2016-09-23 20:55:14

标签: c# web-applications config

我正在尝试从app.config访问一个值,但一直收到以下错误:

'System.Configuration.ConfigurationManager.AppSettings' is not supported by the language

Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'

我的文件顶部有

using System;
using System.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

并且以下行不起作用

string k = System.Configuration.ConfigurationManager.AppSettings["key"];

App.config中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
 </startup>
 <appSettings>
   <add key="key" value="test" />
  </appSettings>
</configuration>

0 个答案:

没有答案