配置系统无法初始化/无法识别配置部分<sectionname> </sectionname>

时间:2012-10-30 09:12:38

标签: .net frameworks

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

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

1 个答案:

答案 0 :(得分:1)

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