.NET 5.0 OnCreateHandle override isn't called
See original GitHub issue- .NET Core Version:
Microsoft.NETCore.App.Ref v5.0.0 Microsoft.WindowsDesktop.App.Ref v5.0.0
- Have you experienced this same bug with .NET Framework?:
No.
Problem description:
When I build this control in .NET Framework and then drag it onto a .NET Framework Windows Form design surface, OnCreateHandle is called and the MessageBox is shown. However, when I build this control in .NET 5.0 (net5.0-windows) with UseWindowsForms true and then drag it onto a .NET 5.0 Windows Forms design surface, OnCreateHandle is not called and the MessageBox does not show.
Expected behavior:
I would expect OnCreateHandle to be called in .NET 5.0 in the same way as it is called in .NET Framework 4.6
Minimal repro:
[Designer(typeof(TestDesigner))]
public class NETFrameworkControl : Control
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.Red, e.ClipRectangle);
}
public class TestDesigner : System.Windows.Forms.Design.ControlDesigner
{
protected override void OnCreateHandle()
{
base.OnCreateHandle();
MessageBox.Show("OnCreateHandle");
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
c# - function overrides not calling
I have a class with a virtual function, and a derived class that overrides it. When I call the function, the override isn't...
Read more >Override method not being called
Hi everyone, I have two methods for using a pressure plate to activate effects on another object. The first script is a component...
Read more >Knowing When to Use Override and New Keywords - C# ...
Because BaseClass now has a Method2 method, a second calling statement can be added for BaseClass variables bc and bcdc , as shown...
Read more >C# design to force the virtual method to be called from ...
Or other times where you call base and the derived class didn't need to because it overrides all the base values rather than...
Read more >Select which .NET version to use
Consider the following scenario: The application specifies that 5.0 is required. When run, version 5.0.* isn't installed, however, 5.1.0 is.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There is a breaking change difference in how Designers work in Framework and .NET, so neither is this a bug, nor is it supposed to work this way.
To create a Designer for VS and .NET, you would need to use the WinForms Designer SDK. The reason is (simplified), that the Designer needs to run in the context of the Form (or the UserControl), which is .NET and not Framework. But VS is Framework. So, for the .NET Designer, there are two processes: The Client Process (Visual Studio, Framework) and a dedicated Server process (.NET) which is called the DesignToolsServer. So principally, and depending on what you need to do, you’d need to provide a NuGet which VS picks up, which holds the code for both the Server and the Client Process. And since the control and most part of the Designer logic is created in the Server process, anything Dialog-UI related needs to be marshalled from the Server process, which is not supposed to handle any dialogs due to potential dead lock concerns, back to the VS-Client.
Docs for the SDK are in the making, they are on our roadmap for the first quarter of this year.
Using the code on the issue itself, I’ve just run it using .NET 6 SDK version 6.0.100-rc.2.21505.57 in Microsoft Visual Studio Enterprise 2022 Preview (64-bit) Version 17.0.0 Preview 5.0, using .NET 6 as the target Framework in the Core4451 project. Unfortunately the issue can still be reproduced - it works in .NET Framework 4.8, but doesn’t work in .NET 6.
Is there approximate timeframe for fixing that in Visual Studio 2022?