Winforms: Inherited forms don't work in the designer for .NET Core

Created on 24 May 2020  路  19Comments  路  Source: dotnet/winforms

  • .NET Core Version:
    3.1

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

Problem description:

  1. Create a .NET Core WinForms app.
  2. Create a form.
  3. Create a second form.
  4. Edit the second form's code behind to make it inherit from the first form.
  5. Open the visual designer for the second form.

The designer will then crash with 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: 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: \r\n Form2 --- The base class 'BrokenFormsInheritance.Form1' could not be loaded. Ensure the assembly has been referenced and that all projects have been built. | 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: 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: \r\n Form2 --- The base class 'BrokenFormsInheritance.Form1' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
-- | --
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: 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: \r\n Form2 --- The base class 'BrokenFormsInheritance.Form1' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

  1. Build the project as the error indicates.

The error will remain regardless of if I build the project.

Expected behavior:

The designer opens.

Minimal repro:

see attached

BrokenFormsInheritance.zip

Priority 2 VS designer

Most helpful comment

This is a designer specific feature, and we've got it on the agenda. We likely won't have it for 16.8 but hopefully in the next VS release. Which control(s) do we not have runtime support for? We've still got a couple of controls to get designer support for as we continue to implement features, and there are a handful of designers that are very specific to our controls and we've gotten most of these into our designer or will have shortly.

All 19 comments

Yep, we've got an internal item on our backlog for this issue.'

Great, thanks!

Any eta? Will this and all .net controls be ready to 5.0?

This is a designer specific feature, and we've got it on the agenda. We likely won't have it for 16.8 but hopefully in the next VS release. Which control(s) do we not have runtime support for? We've still got a couple of controls to get designer support for as we continue to implement features, and there are a handful of designers that are very specific to our controls and we've gotten most of these into our designer or will have shortly.

Which control(s) do we not have runtime support for?

DataGridView :yum:

@kirsan31 we've ported the DataGridView control to Core a long time ago. @RussKie is working on #3875 as we speak. I'm hopeful we can get it approved for 5.0. Are you facing other issues?

cc: @dreddy-work

I am sorry for misleading, by _all .net controls be ready to 5.0_ I mean new designer will be handle them.

@kirsan31 , we did port large portion of the designers for those controls as well. There are very few designers that were low in our priority list based on their usage and are on our list to port as we progress. If you see a specific control that its designer is not working or not available, please let us know.

@dreddy-work as I mentioned above - DataGridView. It's not usable in designer because of not working styles editors (all of them). Some related issue. But for me behavior is not changed from 16.7 Pr. 5 - All style dialogs opening correctly, but produce no code - no changes.
Quick look at ListView bring that item editor not showing color selection dialog. Changing color by double click - immediately apply it to the code regardless if I will press cancel next...

V.S. 16.8 pr. 3.

P.s. I think this is a bit off topic here - do we need create new issue or something?

do we need create new issue or something?

Please raise these issues via the VS Feedback tool, as it captures necessary telemetry such as versions of components, etc.

@RussKie Done: Issue1, Issue2.

@Shyam-Gupta

Regarding inherited Forms: They should work after the application is built. If not then let me know and we can discuss it on the other issue.

I've modified original repro a bit: DesignerInheritence.zip
V.S. 16.8 P. 3.2:

vsi

System.InvalidOperationException: 'Site' must not be null in order to access a required service.
   at WinFormsSurface.Designers.ComponentDesigner.GetRequiredService[T]()
   at WinFormsSurface.Designers.ControlDesigner.SetUnhandledException(Control owner, Exception exception)
   at WinFormsSurface.Designers.ControlDesigner.DesignerWindowTarget.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

V.S. 16.8 P. 4 - same behavior.

Inheritance in general was working fine when you build and open the designer. In this sample app, issue was because of a bug in the DataGridView designer code. This issue fixed today in the designer repo by Dustin and will be available in the VS 16.9 preview2.

Also, original issue was about the inheritance, I think we can close this issue. Let me know if you disagree @kirsan31.

@dreddy-work I've checked our big project and with visual inheritance seems all is ok...
But there were other problems about the new designer. Where to report them? V.S. report tool?

@dreddy-work I've checked our big project and with visual inheritance seems all is ok...
But there were other problems about the new designer. Where to report them? V.S. report tool?

You can always report them via VS feedback tool. And that is preferred way for now for designer related issues. But if you end up reporting here, we might transfer the issue t designer repo ( which is not public) and it would be hard to track the status for you.

As you opened #4139 , closing this issue.

Was this page helpful?
0 / 5 - 0 ratings