appSettings配置部分中不存在密钥"SecurityKey". [英] The key 'SecurityKey' does not exist in the appSettings configuration section.

查看:274
本文介绍了appSettings配置部分中不存在密钥"SecurityKey".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Winform/C#/SQL

尝试运行程序时出现此错误:
appSettings配置部分中不存在密钥"SecurityKey".

程序更准确地运行并显示登录表单,但是当我尝试登录时,它尝试访问app.config页面中的密钥",但似乎找不到它.

这是寻找关键字的行:
字符串键=(字符串)settingsReader.GetValue("SecurityKey",typeof(String));

我会提到,当我构建并运行该程序时,它运行良好,但是如果尝试从\ bin \ Debug文件夹中的.exe运行它,则会出现上述错误.

我相信它指的是我的一门课:
< appsettings>
< add key ="SecurityKey" value =钥匙在这里">
< add key ="ClientSettingsProvider.ServiceUri" value =">


我在网站上发现有人也有相同的错误,他们发现问题是XML区分大小写,并且该人具有< appsettings>而不是< appsettings>
对他有用,但我遍历了我的申请,但找不到任何类似的问题.

我不应该在deb \ bin \ Debug文件夹中使用.exe吗?

非常感谢您的帮助.

〜Chris

Winform / C# / SQL

I get this error when I try to run my program:
The key ''SecurityKey'' does not exist in the appSettings configuration section.

More accurately the program runs and the login form appears but when I attempt to login it tries to access a "Key" in app.config page but it can''t seem to find it.

This is the line that is looking for the Key:
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));

I''ll mention that when I build and run the program it runs fine but if I try to run it from the .exe in the \bin\Debug folder I get the above mentioned error.

I believe it''s referring to one of my classes:
<appsettings>
<add key="SecurityKey" value="Key goes here">
<add key="ClientSettingsProvider.ServiceUri" value="">


I found on a site someone that had the same error and they found the problem was that XML is case sensitive and the person had <appsettings> instead of <appsettings>
and that worked for him but I went through my application and I couldn''t find any similar problem.

Am I not supposed to use the .exe in the deb \bin\Debug folder perhaps?

Any help is much appreciated.

~ Chris

推荐答案

在您的项目中,您应该有一个app.config文件,该文件的部分类似于以下内容:

In your project you should have a app.config file with a section similar to this:

<applicationSettings>
    <WindowsFormsApplication1.Properties.Settings>
        <setting name="SecurityKey" serializeAs="String">
            <value>Hello</value>
        </setting>
    </WindowsFormsApplication1.Properties.Settings>
</applicationSettings>





自动创建的文件称为Settings.settings和Settings.Designer.cs.应该已经创建.

他们将允许您像这样访问设置:





Auto-generated files called Settings.settings and Settings.Designer.cs should have been created.

They will allow you to access the setting like this:

private void button1_Click(object sender, EventArgs e)
{
    String Security = WindowsFormsApplication1.Properties.Settings.Default.SecurityKey;
}




如果转到项目",属性",设置",您将看到一个同步"按钮.单击有时会刷新所有内容(当事情变得时髦时).




If you go to Project, Properties, Settings you will see a button that says Synchronize. Clicking that sometimes gets everything refreshed (when things get funky).


这篇关于appSettings配置部分中不存在密钥"SecurityKey".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆