2

我在新安装的桌面上调试以下代码。检查我的环境很简单。我已经通过互联网搜索了错误,但没有答案可以解决我的问题。我想这可能是由文件系统权限引起的。

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()
4

1 回答 1

2

我已经解决了这个问题,它是由安装不完整的 .net 框架引起的。请参考以下链接以本地化问题的根源“http://www.codeproject.com/Articles/19675/Cracking-the-Mysteries-of-NET-2-0-Configuration”

于 2012-10-31T02:17:02.477 回答