appSettings配置部分中不存在关键的“UserID”

时间:2020-12-19 23:03:02

All of a sudden I start getting this error while trying to open 2 of some 10+ forms in my Window Forms application in designer.

突然之间,我尝试在设计器的Window Forms应用程序中打开大约10个以上的表单中的2个时开始出现此错误。

To prevent possible data loss before loading the designer, the following errors must be resolved: The key 'UserID' does not exist in the appSettings configuration section.

为了防止在加载设计器之前丢失数据,必须解决以下错误:appSettings配置部分中不存在关键字“UserID”。

It used to work fine and I dont' remember doing significant changes to it.

它过去工作正常,我不记得做了重大改变。

The key, of course, is in the appSettings alright, and always was, and the application builds and executes as expected. Only design view for these 2 forms is unaccessible.

当然,关键是在appSettings中,并且始终是,并且应用程序按预期构建和执行。只有这两种形式的设计视图是不可访问的。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="Server" value="MYSERVER" />
        <add key="DataBase" value="MYDB" />
        <add key="UserID" value="MYUSER" />
        <add key="PassWord" value="MYPASS" />
    </appSettings>
</configuration>

One of them is just a Form, the other is a UserControl. None of them inherits from abstract classes or anything like that. Rebuilding or restarting Visual Studio does not help so far.

其中一个只是一个Form,另一个是UserControl。它们都不是从抽象类或类似的东西继承而来的。到目前为止,重建或重新启动Visual Studio无济于事。

Any ideas on fixing it?

修理它的任何想法?

4 个解决方案

#1


And finally, here is what the designer REALLY was complaining about: I had a call to a stored procedure right from the User Control's InitializeComponent(). While it may not be a good idea indeed (separate question material?), I have to say that the error was not presented to me in the best possible way...

最后,这是设计师REALLY抱怨的内容:我直接从User Control的InitializeComponent()调用了存储过程。虽然它确实不是一个好主意(单独的问题材料?),但我不得不说错误没有以最好的方式呈现给我...

#2


Is it possible the config file was moved to a different folder or a new config file was introduced somewhere?

配置文件是否可能被移动到另一个文件夹或某个地方引入了新的配置文件?

#3


Okay, there is something else in common with these 2 forms - they both use one UserControl and there is another error in the designer which says "The variable 'myControl' is either undeclared or was never assigned." (where myControl is the User Control). Maybe I should manually delete it and try re-adding through the designer.

好的,这两种形式还有其他共同之处 - 它们都使用一个UserControl,设计器中还有另一个错误:“变量'myControl'要么未声明,要么从未分配过。” (其中myControl是用户控件)。也许我应该手动删除它并尝试通过设计器重新添加。

#4


You might check to make sure your XML is well-formed. I'm relying on memory here, but I recall getting this error once after copying settings between different config files and the only problem was that I'd overwritten an extra angle bracket when pasting.

您可以检查以确保XML格式正确。我在这里依赖内存,但我记得在不同的配置文件之间复制设置后得到此错误,唯一的问题是我在粘贴时覆盖了一个额外的尖括号。

#1


And finally, here is what the designer REALLY was complaining about: I had a call to a stored procedure right from the User Control's InitializeComponent(). While it may not be a good idea indeed (separate question material?), I have to say that the error was not presented to me in the best possible way...

最后,这是设计师REALLY抱怨的内容:我直接从User Control的InitializeComponent()调用了存储过程。虽然它确实不是一个好主意(单独的问题材料?),但我不得不说错误没有以最好的方式呈现给我...

#2


Is it possible the config file was moved to a different folder or a new config file was introduced somewhere?

配置文件是否可能被移动到另一个文件夹或某个地方引入了新的配置文件?

#3


Okay, there is something else in common with these 2 forms - they both use one UserControl and there is another error in the designer which says "The variable 'myControl' is either undeclared or was never assigned." (where myControl is the User Control). Maybe I should manually delete it and try re-adding through the designer.

好的,这两种形式还有其他共同之处 - 它们都使用一个UserControl,设计器中还有另一个错误:“变量'myControl'要么未声明,要么从未分配过。” (其中myControl是用户控件)。也许我应该手动删除它并尝试通过设计器重新添加。

#4


You might check to make sure your XML is well-formed. I'm relying on memory here, but I recall getting this error once after copying settings between different config files and the only problem was that I'd overwritten an extra angle bracket when pasting.

您可以检查以确保XML格式正确。我在这里依赖内存,但我记得在不同的配置文件之间复制设置后得到此错误,唯一的问题是我在粘贴时覆盖了一个额外的尖括号。