我在新安装的桌面上调试以下代码。检查我的环境很简单。我已经通过互联网搜索了错误,但没有答案可以解决我的问题。我想这可能是由文件系统权限引起的。
static void Main(string[] args)
{
string test = ConfigurationManager.AppSettings["aaa"].ToString();
Console.WriteLine(test);
}
App.config 看起来像:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aaa" value="bbb" />
</appSettings>
</configuration>
我得到如下错误:
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section appSettings
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.get_AppSettings()