2012-10-30 91 views
2

我在新安裝的桌面下面的代碼中進行調試。檢查我的環境很簡單。 我通過互聯網搜索了錯誤,但沒有答案可以解決我的問題。我想也許這是由文件系統權限造成的。配置系統無法初始化/無法識別配置部分<SectionName>

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

我已經解決了這個問題,它是由被安裝了.NET Framework引起不完整的。請參考後續鏈接以本地化您的問題的來源「http://www.codeproject.com/Articles/19675/Cracking-the-Mysteries-of-NET-2-0-Configuration」

相關問題