.net 如何解决 VS2010 Windows 窗体设计器问题(无法加载基类)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7765538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve VS2010 Windows Form Designer issue (base class could not be loaded)
提问by Anthony
I have recently been getting an error in the Windows Forms designer of VS2010SP1 when using inherited UserControls.
我最近在使用继承的 UserControl 时在 VS2010SP1 的 Windows 窗体设计器中遇到错误。
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.
无法为此文件显示设计器,因为无法设计其中的任何类。设计人员检查了文件中的以下类: DebugPanel --- 无法加载基类“UI.Panels.PanelBase”。确保已引用程序集并且已构建所有项目。
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.
PanelBase 是一个 UserControl,它与 DebugPanel 定义在同一个类库中,它也实现了一个接口 IPanel(它又在同一个类库中定义)。IPanel 实现了在不同类库中定义的接口 IBaseItem。
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.
PanelBase 是可正确设计的,项目都可以正确构建并且可以正常工作,但是当我尝试设计任何继承的控件时,设计器失败了。这不仅限于 DebugPanel 控件,而是从 PanelBase 继承的任何控件......我还看到了我使用的具有类似继承层次结构的其他控件的问题。
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.
我一般可以通过清理库UI.Shared2,关闭VS然后再次打开,重建解决方案并打开设计器来临时解决问题。然后这将工作一小段时间,然后再次开始失败。
Does anyone have any suggestions that can resolve this issue permanently without resorting to restarting VS?
有没有人有任何建议可以永久解决此问题而无需重新启动 VS?
Edit:I am targeting the full version of .NET 4 with all libraries.
编辑:我的目标是包含所有库的完整版 .NET 4。
采纳答案by jmoreno
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.
我建议将您的基类放在一个单独的项目中。正如您显然知道的那样,问题在于 VS 正在丢失一些元信息的跟踪,您可以通过退出和重建来找到它。如果基类位于单独的项目中,则清理/重建更有可能使其恢复最新状态。
回答by Avazee
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.
我遇到过同样的问题。我有一个继承自的 Form 对象/基对象,突然间我看到了所有从 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.
我试图回溯并找出最近发生了什么变化,并记得我将我的项目平台目标从任何 CPU 设置为 x64。我将其改回 Any CPU 并解决了问题,然后再次将其设置回 x64 仍然可以解决问题。
This was on VS 2013, by the way.
顺便说一下,这是在 VS 2013 上。
回答by Nolonar
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).
我最近经常遇到这个问题,并找到了一个简单快速的解决方法,并决定分享它(在 VS 2012 上对我有用)。
When you have a Form like this:
当你有这样的表格时:
public partial class MyForm : MyBaseForm
and the designer fails to design MyBaseFormsaying the base class 'System.object' cannot be designed, all I have to do is to remove : MyBaseFormand revert (Backspace > Ctrl + Z). The designer will come to its senses then.
设计师没有设计MyBaseForm说the base class 'System.object' cannot be designed,我所要做的就是删除: MyBaseForm并恢复(退格> Ctrl + Z)。届时,设计师就会清醒过来。
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.
现在剩下要做的就是等待微软修复那个烦人的错误。
回答by sonofsmog
- 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.
如果您显然在调试模式下构建项目,表单设计器将不会重建您手动编辑的表单。
回答by Andrew Kanieski
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.
我经常运行几个 Visual Studio 实例。如果我让 VS 的一个实例在调试模式下运行程序,并且该程序与我尝试在其中设计的 Visual Studio 实例共享一个库,那么我就会遇到这个问题。它也可以像设计者引用的 DLL 一样简单。
Once you close the program that is locking those library files then the designed returns to normal.
一旦关闭锁定这些库文件的程序,设计就会恢复正常。
回答by bakester14
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.
要添加到可能导致此错误的大量问题列表中,似乎从泛型类型或抽象类继承可能会破坏设计人员。
回答by S Bowyer
I had this bug with VS2015, tried clean/rebuild steps, build in release didn't work.
我在 VS2015 中遇到了这个错误,尝试了清理/重建步骤,但在版本中构建不起作用。
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.
我将基本控件放在另一个项目中,但设计师抱怨它没有构造函数。我有一个带有 2 个参数的构造函数,但没有一个空参数。我添加了一个空的构造函数,设计师工作了。然后我将基本控件与派生控件一起移回其原始位置,并且设计器错误又回来了。
I gave up and just put the base control in a "VsBug" project, seems to be happy...
我放弃了,只是将基本控件放在“VsBug”项目中,似乎很高兴......
回答by Payedimaunt
I solved this issue renaming all my forms and user controls and than renaming them back again...
我解决了这个问题,重命名了我所有的表单和用户控件,然后重新命名它们......
For Example:
例如:
And then do the same whit the original name all works now...
然后对原来的名字做同样的事情,现在一切都有效......


