.net - 配置系统无法初始化/无法识别配置节 <SectionName>

标签 .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()

最佳答案

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

关于.net - 配置系统无法初始化/无法识别配置节 <SectionName>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13135787/

相关文章:

.net - 封闭式和封闭式事件的区别

c# - 是否可以一次扩展 2 个类?

c# - .NET (C#) MySqlDbType 用于 char

database - 在模块化/可插拔数据库支持的应用程序框架中进行测试

objective-c - 具有相同符号的两个框架

.net - ASP.NET 延迟作业以运行异步代码?

c# - 获取 wcf 服务程序集中文件的路径

php - 如何在 Zend Framework 2 中打开 PHP 错误报告?

iphone - 创建 iOS 框架

visual-c++ - MFC 是否仍用于新开发(具有任何 Material 量)?