Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Failed to create component 'ControlName' " when dragging a windows forms user control to a form

Tags:

winforms

I have a windows forms user control in my project. It has been working on a form with out any issues but suddenly i can no longer use it on any other form. If i try to drag it from the toolbox to a new form, i get this error message

"Failed to create control 'controlName'. The error message follows: system.ArgumentException: the specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider or not valid."

But when i run the project, it compiles with out any errors.

Also, when i want to open the designer of the form which already contains this Usercontrol and running well, the designer does not load and i see error messages below

"To prevent possible data loss before loading the designer, the following errors must be resolved:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

The variable 'MyControlName1' is either undeclared or was never assigned."

i'M not understanding whats going on but the project still builds and runs but definitely something is seriously wrong.

like image 847
StackTrace Avatar asked Jan 15 '10 08:01

StackTrace


2 Answers

Wrap your user control load methods with:

private void myUserControl_Load(object sender, EventArgs e)
{
    if (!this.DesignMode)
    {
        //....stuff
    }            
}
like image 92
RMuesi Avatar answered Sep 27 '22 17:09

RMuesi


It looks like your control is trying to establish a connection with a database on designtime, and the database cannot be found (probably because the designer tries to look in the Visual Studio bin directory).

Your best bet is not to connect a database to a user control in design time, but dynamically link it during runtime.

like image 33
Webleeuw Avatar answered Sep 27 '22 17:09

Webleeuw