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 に答える