Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorProvider exception when shown a second time after being dragged on another monitor with diiferent DPI #12850

Open
alamarch1 opened this issue Jan 28, 2025 · 6 comments
Assignees
Labels
area-HDPI HDPI, not specific to Dpi mode of app 💥 regression-release Regression from a public release
Milestone

Comments

@alamarch1
Copy link

alamarch1 commented Jan 28, 2025

.NET version

8.0.12

Did it work in .NET Framework?

Not tested/verified

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

Yes:
7.0.20
9.0.0

Issue description

ErrorProvider throws this exception, when displayed for the second time in a Form, which was previously dragged into another monitor with different DPI.

Cannot access a disposed object.
Object name: 'Icon'.

at System.Drawing.Icon.get_Handle()
at System.Windows.Forms.ErrorProvider.IconRegion.get_Handle()
at Windows.Win32.PInvoke.DrawIconEx[T](HDC hDC, Int32 xLeft, Int32 yTop, T hIcon, Int32 cxWidth, Int32 cyWidth)
at System.Windows.Forms.ErrorProvider.ErrorWindow.OnPaint()
at System.Windows.Forms.ErrorProvider.ErrorWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

Note that for the bug to happen, the application HighDpiMode must be set to PerMonitorV2 AND the ErrorProvider object must not have it's Icon property set with a Icon object.

Steps to reproduce

An application sample is attached.
ErrorProviderBug.zip

To reproduce with the example (requires at least two monitors with different DPIs):

  1. Open the application. It's HighDpiMode is set to PerMonitorV2.
  2. Click on the "Open dialog" button. This will create a new Form and open it through a ShowDialog. A TextBox and an ErrorProvider will be created with default values. Initially it is not visible.
  3. Type some text in the TextBox so that we call errorProvider.SetError with a string value, in order to show the error icon.
  4. Move the Form into another monitor.
  5. Close that Form.
  6. Open the Form again through the "Open dialog" button.
  7. Type some text so that we call again errorProvider.SetError with a string value in order to show the error icon.
  8. The exception "Cannot access a disposed object." will appear.

In the sample application, I commented in Form2.cs a set on the property Icon of the errorProvider object, so that you can experiment that if we use a custom Icon, and redo the steps above, the bug won't happen. Same if you set a HighDpiMode other than PerMonitorV2 in Program.cs.

@alamarch1 alamarch1 added the untriaged The team needs to look at this issue in the next triage label Jan 28, 2025
@Tanya-Solyanik Tanya-Solyanik added area-HDPI HDPI, not specific to Dpi mode of app and removed untriaged The team needs to look at this issue in the next triage labels Jan 28, 2025
@Tanya-Solyanik Tanya-Solyanik added this to the 10.0 Preview2 milestone Jan 28, 2025
@Tanya-Solyanik
Copy link
Member

Please find the commit that introduced this issue and see if this is controlled by any quirks.

@merriemcgaw merriemcgaw added the 💥 regression-release Regression from a public release label Jan 29, 2025
@merriemcgaw
Copy link
Member

merriemcgaw commented Feb 11, 2025

@LeafShi1 can your team take a look at this ASAP once the editors are done?

@Tanya-Solyanik
Copy link
Member

@Olina-Zhang - could you please find what commit regressed this?

@LeafShi1
Copy link
Member

LeafShi1 commented Feb 11, 2025

This issue caused by PR #8486 and it was fixed in PR #10850, the changes need to be backport to .net8.0

@Tanya-Solyanik
Copy link
Member

I assume this works on NET10 as expected?

@LeafShi1
Copy link
Member

I assume this works on NET10 as expected?

Yes, it's fine on NET10. I cherry-picked the PR #10850 to .net8.0, please review the PR #12915

@LeafShi1 LeafShi1 self-assigned this Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-HDPI HDPI, not specific to Dpi mode of app 💥 regression-release Regression from a public release
Projects
None yet
Development

No branches or pull requests

4 participants