VS 2012 Designer could not be shown

房东的猫 提交于 2019-12-11 13:55:54

问题


I have a UserControl class Employee_EmployeeKeyOneRelationUC that inherit from RelationUC that inherit from RelationBase that inherit from System.Window.Forms.UserControl

When I try to open my Employee_EmployeeKeyOneRelationUC in the Designer I have this error :

The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: Employee_EmployeeKeyOneRelationUC --- The base class 'AstusFMS.Content.RelationUC' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

But when I open RelationUC and RelationBase both are showing up correctly.

My program still compiling but why this is bothering me ? Because I have a form EmployeeForm that use a lot of UserControl (like Employee_EmployeeKeyOneRelationUC) and when I try to edit something in this Form, every UserControl included in the form that inherit from UserControleBase are deleted (left: TFS Server, right: local) :

This diff is showing that the designer deleted all my ucEmployee* object. Just because I change a ComboBox's name (combobox has no relation with one of the UC).

I have notice that when I create a new UserControl file the default code showing up has an error :

But the Using System.Windows.Forms; is right there. If I change the UserControl for System.Windows.Forms.UserControl it works.

I may not be clear enough so if you have question, i'll be on to answer and test all day.

Tested on 3 different computer with VS2010, VS2012 Update 1, VS2012 Update 2


回答1:


When using generics inside Form or Usercontrol, it's recommended that you put an empty class that define the Generic type. Your current Form then derives from that class.

I put that class inside the same file. It has to be after the actual Form code like this:

  public partial class Employee_EmployeeKeyOneRelationUC
    : Employee_EmployeeKeyOneRelation_GenericUC
  { ... }

  public class Employee_EmployeeKeyOneRelation_GenericUC
    : RelationUC<MyObject>
  { }



回答2:


VS2013 has a a bug with the form designer if you load in from VS2010 a C++ CLR Winforms app. "The designer could not be shown for this file because none of the classes within it can be designed. "

If you change and save the source file then the form designer starts to work again. But it fails again on loading in the project again. Looks like a race between loading the source file and the form designer parsing the code.



来源:https://stackoverflow.com/questions/16088565/vs-2012-designer-could-not-be-shown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!