views:

230

answers:

5

Here's a strange one.

After renaming a class, one of my forms began giving me errors in the designer, refusing to open. Funny thing is, the form worked just fine when I ran the program.

I began reverting my changes to deduce the problem. I have now reverted completely back to the last commit - in which I know the form was working in the designer - cleaned the solution, and deleted the bin/ and obj/ folders, as well as the *.suo file for good measure.

The form still does not display in designer.


Here are the errors it gives:

  1. Could not find 'MyNamespace.MyControl'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
  2. The variable 'myControl1' is either undeclared or was never assigned.

The variable is both declared and assigned, and MyControl builds fine (again, the form works fine when the program is actually run). Stranger still, if I try to create a new form and drag a MyControl onto it, I get this Entity-Framework error:

Failed to create component 'MyControl'. 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. at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) at System.Data.EntityClient.EntityConnection..ctor(String connectionString) at System.Data.Objects.ObjectContect.CreateEntityConnection(String connectionString) etc. etc.

There is nothing wrong with my connection string: it worked before, and, again, it works when I actually run the program (the control already exists on the old form from the previous commit).


Any ideas whatsoever? I am completely at a loss.


[Edit] The only significant code:

MyControl.cs
public MyControl()
{
    _entities = new MyEFEntities(); //Entity-framework generated class
}

MyForm.Designer.cs
private void InitializeComponent()
{
    this.myControl1 = new MyNamespace.MyControl();
    ...
    this.Controls.Add(this.myControl1);
}

MyEFDatabase.Designer.cs
public MyEFEntities() : base("name=MyEFEntities", "MyEFEntities") { ... }

App.Config
<connectionStrings>
    <add name="MyEFEntities" connectionString="metadata=res://*/MyEFDatabase.csdl|res://*/MyEFDatabase.ssdl|res://*/MyEFDatabase.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyDatabaseServer;Initial Catalog=MyDatabase;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

I've tried the "replace &quot; with '" trick - didn't help.


[Edit2] It is happening to new projects also, but not immediately. Only after fiddling around a bit (it has something to do with adding a many-to-one relationship that EF did not figure out on its own), but I can't figure out the exact steps to reproduce.

A: 

Have you tried deleting the designer.cs file then right-clicking on the aspx page and selecting 'Convert to Web Application?' It re-gens the designer file and usually works for me when I have weird designer issues.

IniTech
This is a winforms app, and I highly doubt it is a problem with the generated code; it is just a window with a control in it, so the code I listed above is literally all the relevant code.
BlueRaja - Danny Pflughoeft
A: 

Did you try excluding/including the offending form from the project? That's worked for me in the past.

Big Endian
+2  A: 

I'd suggest closing all forms open in design mode; rebuild all, and then see if they work when you reopen the form designer -- I've had issues in the past where it failed to generate the control library because it was locked in memory (by the form designer).

Rowland Shaw
A: 

Have you successfully built your project since you changed the name of the class? The designer can only load the components from built assemblies.

EDIT: another thing to check is the size of the .resx file. I sometimes find that mine has been truncated, and I have to delete it or restore it from source control.

Simon
Yes, but I changed the name back; again, I reverted *all* the code back to its original form.
BlueRaja - Danny Pflughoeft
@BlueRaja: have you done a build since?
Simon
Yes I have cleaned and built many, many times. I've also deleted the bin/ and obj/ folders, and the *.suo file.
BlueRaja - Danny Pflughoeft
A: 

I've posted a bug-report, along with a workaround, here.

The only workaround is to create the EF_Entities within the form, and pass it in as a parameter to the control.

This workaround no longer works if the parameter is a member of a parent of the control ie. MyChildControl : MyParentControl, MyParentControl : UserControl, EF_EntitiesParameter member of MyParentControl. The designer crashes with the error "Object reference not set to an instance of an object"; futher inspection shows that the designer is running code that requires EF_EntitiesParameter, which for some reason is set to null (it is being correctly set in the form's constructor, and works fine when actually running).

The workaround to this problem is to prevent all code that requires the use of EF_EntitiesParameter from running in the designer (See workarounds here)

BlueRaja - Danny Pflughoeft