C# - 编译器错误:System.Configuration.ConfigurationErrorsException 未处理

发布于 2024-10-22 23:50:33 字数 1930 浏览 6 评论 0原文

嘿大家, 如何修复在“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

这是 Properties 目录下的 Settings.Designer.cs 文件中的代码:

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

这是 bin 文件夹中 CCP_Utility.exe.config 的代码:

  <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>

< 是什么意思? CCP_Utility.Settings1 >标签必须匹配到? App.config 还有什么?

大小写重要吗?我将变量声明为 TargetDir Settings.Settings...

System.Configuration.dll 文件位于何处?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铃予 2024-10-29 23:50:37

我通过更改 Settings1.Designer.cs 文件中 CCP_Utility.Settings1 下的 sourceDir 和 targetDir 的大小写,使应用程序编译时没有编译器错误,如下所示:

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

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>
羁拥 2024-10-29 23:50:37

验证 UserScopedSettingAttribute 与正确的设置部分匹配。

如果我没记错的话,是的,区分大小写。

通常,我会添加一个设置,保存并关闭,然后再次打开设置设计器,然后删除该设置,保存并关闭。这将使设计师保持同步。我见过第一次在计算机上打开设计器时它们不同步。 (例如,当您从源代码控制获取时。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文