question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Major regression in Form.ShowDialog(IWin32Window) in .NET 7 -- ship blocker for Paint.NET 5.0

See original GitHub issue

.NET version

7.0.0

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, it worked fine in .NET 5 and .NET 6

Issue description

When Form.ShowDialog(IWin32Window) is called with a Control instead of a Form, the dialog’s parenting/ownership is not set correctly, causing the dialog to not “track” with the parent form correctly.

The most visible symptom of this is that if you switch between virtual desktops, the parent form is correctly hidden but the dialog is not. And, it is possible to interact with the main window in certain ways. In my app (Paint.NET), it is possible to switch between images by using the taskbar (kind of like how IE/Edge used to let you switch between tabs). This is normally prevented when a modal dialog is active, but right now it’s not. This can result in actions affecting the wrong image, which then corrupts the state of the image’s change history and causes data loss.

Another symptom is that the Owner for the dialog is null, even though it should probably be control.FindForm()

This is currently a ship-blocker for Paint.NET 5.0 on .NET 7. I cannot release the new version with this bug.

Known workaround: use dialog.ShowDialog(control.FindForm() instead of dialog.ShowDialog(control). However, this requires changes to many places in the code, and is not a fix I can apply to libraries or plugins.

I believe this regressed due to https://github.com/dotnet/winforms/pull/3394 cc @dreddy-work which changed whether Owner was set or SetWindowLong(..., GWL.HWNDPARENT, ...) was called. Previously, SetWindowLong was always called.

Steps to reproduce

Create a Form and do Application.Run(form). Make sure the Form has at least 1 child control, like a button. In some code within the form, like in the button’s click handler, create another Form and call dialog.ShowDialog(button) While the dialog is open, switch between virtual desktops using WinKey+Shift+Left/Right

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
Olina-Zhangcommented, Nov 25, 2022

Tested this issue in .Net 6.0, 7.0 and the latest 8.0 builds using above sample application: can reproduce it in .Net 7.0 and 8.0. ShowDialogBug.zip

.Net 6.0: image

.Net 7.0 and 8.0: image

4reactions
rickbrewcommented, Nov 26, 2022

I built my own version of System.Windows.Forms.dll with the fix, and I can thankfully confirm that it does fix the issues I was seeing in Paint.NET

Looks like I’ll have to ship my own S.W.F.dll for the time being, but this is preferable to rolling back to .NET 6. phew!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ship blocker for Paint.NET 5.0 · dotnet/winforms@5a28fa9
Major regression in Form.ShowDialog(IWin32Window) in .NET 7 -- ship blocker for Paint.NET 5.0 #4121. Sign in to view logs · Sign in to...
Read more >
Publish paint.net with Microsoft Intune?
Hello @all, I tried to publish paint.net 5.0.7 in Microsoft Intune but get a installation failure. I've used the MSI-file with these ...
Read more >
paint.net 4.2.17 alpha build 7858 -- now using .NET 5!
This seems to be a bug in .NET 5. Edit: These were patched up in a later release and work fine now. No...
Read more >
Roadmap and Change Log
Roadmap and Change Log paint.net 5.0.9 - released on August 8th, 2023. This is a small update that fixes a few important bugs....
Read more >
paint crashes if you do a selection glitch and then history- ...
After finalizing the selection, paint.net still used over 1GB. Even if you close all images it still uses that amount. The Selection finalizing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found