How to resolve VS2010 Windows Form Designer issue (base class could not be loaded)
I have recently been getting an error in the Windows Forms designer of VS2010SP1 when using inherited UserControls.
The error is
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: DebugPanel --- The base class 'UI.Panels.PanelBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
PanelBase is a UserControl that is defined in the same class library as DebugPanel that also implements an interface IPanel (which is in turn defined in the same class library). IPanel implements an interface IBaseItem that is defined in a different class library.
So we have
DebugPanel 开发者_开发百科(Library UI.Shared2)
- PanelBase (Library UI.Shared2)
- UserControl (System.Windows.Forms - .NET4)
- IPanel (Library UI.Shared2)
- IBaseItem (Library Net.Common)
PanelBase is designable correctly, the project all builds correctly and works but when I try and design any inherited control the designer fails. This is not limited to the DebugPanel control, but any control inheriting from PanelBase... I've also seen the issue with other controls that I use that have similar inheritance hierarchies.
I can generally resolve the problem temporarily by cleaning the library UI.Shared2, closing VS and then opening it again, rebuilding the solution and opening the designer. This will then work for a short while and then start to fail again.
Does anyone have any suggestions that can resolve this issue permanently without resorting to restarting VS?
Edit: I am targeting the full version of .NET 4 with all libraries.
I had the same issue. I had a Form object/base object I was inheriting from, and all of a sudden I see this message for all Forms that were inheriting from the Base.
I tried to backtrack and figure out what changed recently and remembered I set my project Platform Target from Any CPU to x64. I changed it back to Any CPU and the problem got resolved, and then setting it back again to x64 still kept the problem fixed.
This was on VS 2013, by the way.
I've been having this issue a lot recently and found an easy and fast workaround and decided to share it (works for me on VS 2012).
When you have a Form like this:
public partial class MyForm : MyBaseForm
and the designer fails to design MyBaseForm
saying the base class 'System.object' cannot be designed
, all I have to do is to remove : MyBaseForm
and revert (Backspace > Ctrl + Z). The designer will come to its senses then.
public partial class MyForm : MyBaseForm // The designer has trouble with this
public partial class MyForm // Force an error
public partial class MyForm : MyBaseForm // Revert back, the designer should now work again
All that's left to do now, is to wait for Microsoft to fix that annoying bug.
I would suggest putting your base class in a separate project. As you obviously know, the problem is that VS is losing track of some meta information, which you can get it to find by quitting and rebuilding. If the base class is in a separate project, a clean/rebuild is more likely to bring it back up to date.
- Clean Project (not sure if this is necessary)
- Set build to Release
- Rebuild Project
The forms designer will not rebuild the forms that you manually edited if you build the project in Debug mode apparently.
I also have found that when you are trying to design a form that may have referenced libraries that are already in use, then it fails to design.
I often run several Visual Studio instances. If I leave an instance of VS running a program in debug mode, and that program shares a library with the instance of Visual Studio in which I am trying to design, then I run into this problem. It also can be as simple as the DLL that the designer references is in use.
Once you close the program that is locking those library files then the designed returns to normal.
I solved this issue renaming all my forms and user controls and than renaming them back again...
For Example:
My user control...
Right click on..,
Renaming...
And then do the same whit the original name all works now...
To add to this extensive list of issues that could cause this error, it seems that inheriting from a generic type or abstract class can screw the designer.
I had this bug with VS2015, tried clean/rebuild steps, build in release didn't work.
I put the base control in another project and the designer complained that there wasn't a constructor for it. I had a constructor with 2 arguments, but no empty one. I added an empty constructor and the designer worked. I then moved the base control back in it's original location with the derived controls, and the designer bug came back.
I gave up and just put the base control in a "VsBug" project, seems to be happy...
精彩评论