2010-03-16 53 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