尝试从WinForms用户设置读取时出现ConfigurationErrorsException

时间:2015-09-21 19:33:04

标签: c# winforms exception

之前我已经查看了此问题的上一次迭代,但我无法使用这些答案解决我的问题,所以这里有...

目前正在使用C#Windows窗体中的用户设置。这是我的整个App.config文件。它由Visual Studio自动生成,因此在打开它以诊断为什么抛出此异常之前,我没有触及它。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
      <sectionGroup name="userSettings"    type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089" >
          <section name="MyProject.General" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
          <section name="MyProject.Settings.General" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
      </sectionGroup>
  </configSections>
  <startup> 
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <userSettings>
    <MyProject.General>
        <setting name="StoreName" serializeAs="String">
            <value />
        </setting>
    </MyProject.General>
      <MyProject.Settings.General>
          <setting name="StoreName" serializeAs="String">
              <value />
          </setting>
          <setting name="StoreAddress" serializeAs="String">
              <value />
          </setting>
          <setting name="StorePhone" serializeAs="String">
              <value />
          </setting>
          <setting name="ReqSettingsPassword" serializeAs="String">
              <value>False</value>
          </setting>
          <setting name="SettingsPassword" serializeAs="String">
              <value />
          </setting>
          <setting name="ReqInventoryPassword" serializeAs="String">
              <value>False</value>
          </setting>
          <setting name="InventoryPassword" serializeAs="String">
              <value />
          </setting>
          <setting name="ReqManagerOverride" serializeAs="String">
              <value>False</value>
          </setting>
          <setting name="ManagerOverride" serializeAs="String">
              <value />
          </setting>
      </MyProject.Settings.General>
  </userSettings>

异常是指这段代码:

[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string StoreName {
    get {
        return ((string)(this["StoreName"])); // * helper points to this line *
    }
    set {
            this["StoreName"] = value;
    }
}

是的,当我给出&#34; StoreName&#34;时会发生同样的错误。默认的非空值。

据我所知,这个文件看起来应该是这样(甚至将configSections标签作为configuration的第一个孩子等等) - 再次,这是Studio生成的文件,所以在遇到这个例外之前我并没有弄乱它。

0 个答案:

没有答案