Skip to content

DesignerHost.CreateComponent throws NotImplemetedException #4456

@phillipstoll

Description

@phillipstoll
  • .NET Core Version:

.NET SDK 5.0.101 - .NET Framework 5.0

  • Have you experienced this same bug with .NET Framework?:

No, the bug does not happen in .NET 4.8

Problem description:
DesignerHost.CreateComponent throws NotImplemetedException with message:
This method/object is not implemented by design.

System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(System.Type componentType, string name) Line 712	C#
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(System.Type componentType) Line 682	C#
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignSurface.DefaultDesignerLoader.BeginLoad(System.ComponentModel.Design.Serialization.IDesignerLoaderHost loaderHost) Line 329	C#
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignerHost.BeginLoad(System.ComponentModel.Design.Serialization.DesignerLoader loader) Line 239	C#
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignSurface.BeginLoad(System.ComponentModel.Design.Serialization.DesignerLoader loader) Line 123	C#
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignSurface.BeginLoad(System.Type rootComponentType) Line 132	C#
 	DesignSurfaceExtNet5.dll!DesignSurfaceExtNet5.DesignSurfaceExt.CreateRootComponent(System.Type controlType, System.Drawing.Size controlSize) Line 107	C#
 	DemoConsoleNet5.dll!DemoConsoleNet5.MainForm.CreateDesignSurface(int n) Line 108	C#
 	DemoConsoleNet5.dll!DemoConsoleNet5.MainForm.InitFormDesigner() Line 29	C#
 	DemoConsoleNet5.dll!DemoConsoleNet5.MainForm.MainForm_Load(object sender, System.EventArgs e) Line 239	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.OnLoad(System.EventArgs e) Line 2625	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.OnCreateControl() Line 2501	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) Line 3548	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() Line 3513	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WmShowWindow(ref System.Windows.Forms.Message m) Line 8348	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 8461	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Line 998	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) Line 1195	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.WmShowWindow(ref System.Windows.Forms.Message m) Line 4189	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Line 4280	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 12276	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 12304	C#
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 196	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	System.Windows.Forms.dll!System.Windows.Forms.Control.SetVisibleCore(bool value) Line 7347	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.SetVisibleCore(bool value) Line 1491	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Interop.Mso.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 1929	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Interop.Mso.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 1867	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form form) Line 794	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) Line 3514	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() Line 3453	C#
 	DemoConsoleNet5.dll!DemoConsoleNet5.Program.Main(string[] args) Line 42	C#

I am porting from .NET 4.8 to 5.0 a report designer that features a drag and drop design surface and uses WinForms. Everything works except for this.
I also ported from .NET 3.5 to 5.0 this project (https://www.codeproject.com/Articles/24385/Have-a-Great-DesignTime-Experience-with-a-Powerful) and everything works except for this.
Using dotPeek to step into the .NET 5.0 code I got as far as DesignerHost.CreateComponent, but I didn't find the method that throws the exception.

Expected behavior:
DesignerHost.CreateComponent returns the requested component

Minimal repro:

  1. create a Windows Forms App using .NET 5.0 Framewok
  2. create a class DesignSurfaceExt that inherits System.ComponentModel.Design.DesignSurface
  3. initialize DesignSurfaceExt by calling ServiceContainer.AddService(typeof(INameCreationService), _nameCreationService);
  4. call rootComponent = (Form)designSurfaceExt.CreateRootComponent(typeof(Form), new Size(640, 480));
    expected: CreateRootComponent returns a new Form
    actual: DesignerHost.CreateComponent throws NotImplemetedException with message 'This method/object is not implemented by design.'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions