C# - Compiler Error: System.Configuration.ConfigurationErrorsException was unhandled

◇◆丶佛笑我妖孽 提交于 2020-01-16 03:28:41

问题


Hey Everyone, How do I fix the Compiler Error upon compiling on "return ((string)(this["TargetDir"]));":

  System.Configuration.ConfigurationErrorsException was unhandled
  Configuration system failed to initialize
  {"Unrecognized configuration section userSettings/CCP.Settings1. (C:\\Users\\bmccarthy\\Documents\\Visual Studio 2008\\Projects\\CCP Utility\\CCP Utility\\bin\\Debug\\CCP_Utility.exe.config line 21)"}

  A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll

Here's the code in my Settings.Designer.cs file under the Properties directory:

    [global::System.Configuration.UserScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("")]
    public string TargetDir {
        get {
            return ((string)(this["TargetDir"]));
        }
        set {
            this["TargetDir"] = value;
        }
    }

Here's the code for CCP_Utility.exe.config from the bin folder:

  <CCP_Utility.Properties.Settings>
    <setting name="SourceDir" serializeAs="String">
      <value />
    </setting>
    <setting name="TargetDir" serializeAs="String">
      <value />
    </setting>
    <setting name="CorpID" serializeAs="String">
      <value />
    </setting>
  </CCP_Utility.Properties.Settings>

    <CCP_Utility.Settings1>
        <setting name="sourceDir" serializeAs="String">
            <value />
        </setting>
        <setting name="targetDir" serializeAs="String">
            <value />
        </setting>
    </CCP_Utility.Settings1>

What does the < CCP_Utility.Settings1 > tag have to match up to?? App.config and what else?

Does capitalization matter? I have the variable declared as TargetDir Settings.Settings....

Where is the System.Configuration.dll file located?


回答1:


Verify UserScopedSettingAttribute matches up with the correct settings section.

If I remember correct, yes, case-sensitive.

Usually, I will add a setting, save and close, then open the settings designer again, and delete the setting, save and close. This will get the designer in-sync. I have seen them get out-of-sync the first time the designer is opened on a computer. (For example, when you get from source control.)




回答2:


I got the application to compile without compiler errors by changing the capitilzation of sourceDir and targetDir under CCP_Utility.Settings1 in the Settings1.Designer.cs file as follows:

<CCP_Utility.Settings1>
    <setting name="SourceDir" serializeAs="String">
        <value />
    </setting>
    <setting name="TargetDir" serializeAs="String">
        <value />
    </setting>
</CCP_Utility.Settings1>


来源:https://stackoverflow.com/questions/5316999/c-sharp-compiler-error-system-configuration-configurationerrorsexception-was

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!