VS2010: How to avoid problems with Windows Forms designers when working with inherited user controls?

Problem. Windows Forms Designer does not work for an inherited user control when the base class implements an interface from another assembly.

Platform: VS 2010 SP1, .NET 4.0 Framework

Error:

A designer cannot be shown for this file, because none of the classes inside it can be designed. The designer examined the following classes in the file: MyControl --- The base class "MyBaseControlLib.MyBaseControl" may not load. Make sure that the assembly has been indicated and that all projects have been built.

in the System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument (IDesignerSerializationManager manager) System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad (IDesignerMenerleMenialDesignerManagerMesser .VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted (Int32 fReload)

I have a solution with 3 library class projects:

MyInterfaceLib:

namespace MyInterfaceLib { public interface IMyInterface { void Foo(); } } 

MyBaseControlLib:

 namespace MyBaseControlLib { using System.Windows.Forms; using MyInterfaceLib; public partial class MyBaseControl : UserControl, IMyInterface { public MyBaseControl() { InitializeComponent(); } public void Foo() { } } } 

MyDerivedLib:

 namespace MyDerivedControlLib { using MyBaseControlLib; public partial class MyControl : MyBaseControl { public MyControl() { InitializeComponent(); } } } 

Although the designer works for MyBaseControl, he does not work for MyControl. If MyBaseControl does not implement IMyInterface, the designer also works for MyControl.

Any ideas?

Thanks Robert

+6
visual-studio-2010 winforms designer
source share
1 answer

We had the same problem. We used the desktop by creating the MyControlDesign class, which is inherited by the MyControl class.

  public partial class MyControl : MyControlDesign { public MyControl() { InitializeComponent(); } } public partial class MyControlDesign : MyBaseControl { public MyControlDesign ():base() { } } 
+2
source share

All Articles