2010-03-16 50 views
3

这是一个奇怪的。疯狂VS设计师错误

重命名一个类后,我的一个表单开始给我设计师的错误,拒绝打开。有趣的是,当我运行程序时,表单工作得很好。

我开始恢复我的更改以推导出问题。我现在已完全恢复到最后一次提交 - 其中知道表单在设计器中工作 - 清理解决方案,并删除bin /和obj /文件夹,以及* .suo文件以获得更好的度量。

窗体仍然不显示在设计器中。


下面是它给人的错误:

  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.

的变量都宣布和分配,以及MyControl建立精细(再次,窗体时程序实际运行正常工作)。更奇怪的是,如果我尝试创建一个新的形式,并将一个MyControl到它,我得到这个实体框架错误:

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.

有什么错我的连接字符串:它的工作之前,并再次, 它在我实际运行程序(该控件已经存在于上一次提交的旧窗体上)时起作用。


任何想法任何?我完全不知所措。


[编辑] 唯一显著代码:

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> 

我已经试过“替换&quot;'绝招 - 没有帮助。


[EDIT2]这是发生在新项目也有,但是不会立即进行。只有在摆弄了一下之后(这与添加EF自己无法解决的多对一关系有关),但我无法弄清楚重现的确切步骤。

+2

通常遇到这种情况时我只需重新启动VS和错误随风 – Luiscencio 2010-03-16 17:31:26

+0

没有运气走开 - 刚刚完成重新启动我的电脑,它仍然发生。 – 2010-03-16 17:36:56

+0

mmmm my next guess = P .... are namespaces OK? – Luiscencio 2010-03-16 17:39:45

回答

0

我发布了一个错误报告,以及一个解决方法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)

0

您是否尝试删除designer.cs文件,然后右键单击aspx页面并选择“转换为Web应用程序?”。它重新设计了设计器文件,当我有奇怪的设计器问题时通常适用于我。

+1

这是一个winforms应用程序,我非常怀疑这是生成的代码的问题;它只是一个带有控件的窗口,所以我上面列出的代码实际上是所有相关的代码。 – 2010-03-16 18:41:36

0

您是否尝试从项目中排除/包含违规表单?这在过去对我很有用。

2

我建议关闭在设计模式下打开的所有窗体;重建所有,然后看看它们是否在你重新打开表单设计器时工作 - 过去,由于它被锁定在内存中(由表单设计器),因此无法生成控件库。

0

自从您更改了班级名称后,您是否成功构建了项目?设计人员只能从构建的装配中加载组件。

编辑:另一件要检查的是.resx文件的大小。我有时会发现我的内容已被截断,我必须将其从源代码管理中删除或恢复。

+0

是的,但我改回了名字;再次,我将所有*代码恢复到原来的形式。 – 2010-03-17 13:17:48

+0

@BlueRaja:你有没有做过构建? – Simon 2010-03-17 13:33:36

+0

是的,我已经清理过很多次。我也删除了bin /和obj /文件夹和* .suo文件。 – 2010-03-17 13:44:29