dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.37k stars 966 forks source link

Designer removes needed code #5915

Open MisinformedDNA opened 2 years ago

MisinformedDNA commented 2 years ago

Problem description:

When I try to edit a control from the designer. The designer will remove needed parts of the code from *.Designer.cs which results in run-time errors.

Expected behavior:

Designer doesn't remove necessary code.

Minimal repro:

  1. Open control in designer
  2. Edit a property

Designer removed the assignment of two fields resulting in NullReferenceExceptions at run-time.

Video

Code

~Code after designer changes~ New after changes

NOTE: I inherited this code and have never used the designer on this control before, so maybe something the designer.cs or resx files are invalid in some way?

dotnet --info > ❯ dotnet --info > .NET SDK (reflecting any global.json): > Version: > Commit: e627d556a1 > > Runtime Environment: > OS Name: Windows > OS Version: 10.0.18363 > OS Platform: Windows > RID: win10-x64 > Base Path: C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\ > > Host (useful for support): > Version: 6.0.0-rc.1.21451.13 > Commit: d7619cd4b1 > > .NET SDKs installed: > 3.1.409 [C:\Program Files\dotnet\sdk] > 5.0.400 [C:\Program Files\dotnet\sdk] > 5.0.401 [C:\Program Files\dotnet\sdk] > 6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk] > > .NET runtimes installed: > Microsoft.AspNetCore.All 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] > Microsoft.AspNetCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] > Microsoft.AspNetCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] > Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] > Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] > Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] > Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] > Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] > Microsoft.NETCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.NETCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] > Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] > Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] > Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] > Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] > Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] > Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] > Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] > Microsoft.WindowsDesktop.App 6.0.0-rc.1.21451.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] >
Tanya-Solyanik commented 2 years ago

DevExpress package used in the project probably does not have the Code designers.

    <PackageReference Include="DevExpress.Win.Reporting" Version="21.1.5" />
MisinformedDNA commented 2 years ago

But the ones disappearing are a DataSet and a TableAdapter. Also, DevExpress has a pretty mature library, if there is a bug with their code, I'd love to be able to tell them what is wrong. I spent hours narrowing this down, so any help is much appreciated.

MisinformedDNA commented 2 years ago

@Tanya-Solyanik I didn't want to edit the designer file for my repro, but I went ahead and did it. DevExpress is now removed as a dependency. I updated main and here's the new change commit. Same issue.

RussKie commented 2 years ago

@MisinformedDNA have you contacted DevExpress?

MisinformedDNA commented 2 years ago

@RussKie I shared a repro with DevExpress removed. It's clearly not them.

MisinformedDNA commented 2 years ago

I've also tested this on VS 2019 and 2022 previews that do not have any DevExpress extensions installed.

dreddy-work commented 2 years ago

@KlausLoeffelmann , can you take a look at the sample here and see anything stand out?

MisinformedDNA commented 2 years ago

@KlausLoeffelmann Have you had a chance to look?

MisinformedDNA commented 2 years ago

@KlausLoeffelmann @dreddy-work Can I get some help? How do I get this resolved?

KlausLoeffelmann commented 2 years ago

Hey @MisinformedDNA,

thanks for reporting that. We would need a repo which doesn't use a third party custom control, of which we don't know how compatible it is with the new designer.

Please also note that Designer support for Typed DataSets is limited for .NET WinForms Apps, since the Data Source Provider Service (which are necessary for maintaining Typed DataSets and get the necessary components into a Form/UserControl on demand) is not available for .NET apps.

That said, the most important scenarios we enabled (in WinForms! WPF is a different story, btw) without resorting to the Data Source Provider Service, so, I'd be interested if we can find a purely WinForms based scenario for this, since this would need to be fixed then!

MisinformedDNA commented 2 years ago

@KlausLoeffelmann The project does not depend on a 3rd party, that dependency was removed Oct 5 (see above).

The note about designer support for Typed DataSets is more of an FYI, since I'm using WinForms? Is that correct?

KlausLoeffelmann commented 2 years ago

The note about designer support for Typed DataSets is more of an FYI, since I'm using WinForms? Is that correct?

No, there might be issues, but I never personally encountered code-loss with using them. And sorry, I was watching your video primarily and saw it had the dependency to DevExpress. I missed that you removed that dependency. I would need to investigate some more, but it's taking a few days at least, so I'd ask to hang in there for a bit longer!

MisinformedDNA commented 2 years ago

@KlausLoeffelmann Thanks for looking into it!

MisinformedDNA commented 2 years ago

@KlausLoeffelmann Any update?

RussKie commented 2 years ago

@KlausLoeffelmann is currently OOF. With the holiday season is almost upon us our responses may be delayed.

KlausLoeffelmann commented 2 years ago

That said, I know my debt, even watching my Mom-visiting-from-Germany backing Holiday cookies. Will take a while though, still... 🎅

merriemcgaw commented 2 years ago

@KlausLoeffelmann getting this back on your radar.

KlausLoeffelmann commented 2 years ago

Follow up question: From your demo, I can't really see for component the generated code is swallowed. Can you provide the sample without any references to third party controls, so I can debug into the repo?

Are you using a .NET Framework control by any chance in the context of a .NET (Core) application?

MisinformedDNA commented 2 years ago

You guys keep asking about a sample without third party controls, but the linked code in OP does not use any third party controls.