1

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) :

Diff for EmployeeForm.Designer.cs (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 : Default UserControl with 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

poudigne
  • 1,694
  • 3
  • 17
  • 40
  • Do you have a namespace in your solution with "UserControl" in the path? It works when you fully qualify it because it's able to distinguish between the class you intend and the namespace you don't. – Alan Apr 18 '13 at 16:41
  • Yup I do, didn't think about that. That's one problem fixed. Have you an idea about the UC that won't show up and my delete code ? – poudigne Apr 18 '13 at 17:04
  • [This question may help you out](http://stackoverflow.com/questions/6683255/the-designer-could-not-be-shown-for-this-file-because-none-of-the-classes-within) – Alan Apr 18 '13 at 17:42

2 Answers2

4

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>
  { }
wizmagister
  • 354
  • 1
  • 10
  • 1
    It works, thank you very much. What a silly workaround, but it works ! – poudigne Apr 18 '13 at 17:49
  • this didn't help for me – Boogier Feb 03 '14 at 09:06
  • Thank you very much, it works but I consider too, that is silly way. So I gave up. Besides, I have to add that, when I try to solve this problem, I used one constructor with a parameter in the class derives from generic form. But it didn't work. Then I added an empty constructor and it worked again. It's an interesting error... – bafsar Apr 22 '15 at 03:13
1

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.

Nigel
  • 11
  • 1