日期:2014-05-18  浏览次数:20881 次

读配置文件出现"Configuration system failed to initialize"是什么问题啊?
配置文件是:
HTML code

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <AppSettings>
    <add key="password" value="123456" />
  </AppSettings>
</configuration>



读取是:
C# code

public string GetAppConfig(string strKey)
        {
            try
            {
                foreach (string key in ConfigurationManager.AppSettings)
                {
                    if (key == strKey)
                    {
                        return ConfigurationManager.AppSettings[strKey];
                    }
                }
                return null;
            }
            catch(System.Exception ex)
            {
                Console.WriteLine("{0} GetAppConfig()Exception caught.", ex);
                return null;
            }

        }



为何foreach (string key in ConfigurationManager.AppSettings)
时总抛出异常呢?

------解决方案--------------------

大小写?、

AppSetting

----->

appSettings