The key 'UserID' does not exist in the appSettings configuration section

孤街浪徒 提交于 2019-12-20 05:41:09

问题


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.

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.

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.

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

Any ideas on fixing it?


回答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...




回答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.




回答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.



来源:https://stackoverflow.com/questions/427007/the-key-userid-does-not-exist-in-the-appsettings-configuration-section

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