views:

785

answers:

4

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?

A: 

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

Kon
It's the only config file, and I don't think it was moved.I also tried checking in the solution, getting the latest version to a different empty folder and rebuilding it. Still runs properly, and the designer for the 2 forms still gives the same error.
Evgeny
A: 

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.

Evgeny
+1  A: 

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

Evgeny
Extremely annoying error, I got the same error in WPF because I was setting up a sql database connection, and calling the app.config to return the required value;sqlserver.DataBase = (string)configurationAppSettings.GetValue("DataBase", typeof(string));
wonea
A: 

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.

Matt