Repository navigation
Fix ComboBox crash during handle creation with autocomplete on non-system-DPI monitors - #15298
Merged
LeafShi1 merged 1 commit intoOct 23, 2026
Conversation
…stem-DPI monitors
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15298 +/- ##
=============================================
Coverage 37.84861% 37.84861%
=============================================
Files 246 246
Lines 9789 9789
Branches 1031 1031
=============================================
Hits 3705 3705
Misses 5920 5920
Partials 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow lifecycle guard addresses the reported crash while focused regression tests cover both the corrected and preserved behavior.
No open issues 🎉
What changed in this PR
Fixes #15286 by preventing ComboBox handle destruction when DPI scaling changes an explicitly assigned font during handle creation.
Changes:
- Skip autocomplete-related handle recreation while handle creation is in progress.
- Preserve handle recreation for subsequent font changes.
- Add regression tests across all autocomplete modes, checking handle lifecycle and retained item functionality.
| File | Description |
|---|---|
| src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs | Tests font changes during and after handle creation across autocomplete modes. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.cs | Guards autocomplete-related handle recreation with the handle-creation state. |
Review effort: Balanced
Shyam-Gupta
approved these changes
Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15286
Root cause
Starting with .NET 7, per-monitor V2 DPI handling can scale an explicitly assigned font during
Control.OnHandleCreated, synchronously invokingComboBox.OnFontChanged.When
AutoCompleteModeis notNone,ComboBox.OnFontChangedunconditionally recreates the handle. This destroys the handle while its initial creation is still in progress. The nested creation attempt returns early becauseStates.CreatingHandleis set, leaving the remaining ComboBox initialization without a valid handle..NET 6 has the same autocomplete-related handle recreation logic, but its handle-creation DPI path does not perform the font scaling that triggers this reentrancy.
Proposed changes
ComboBox.OnFontChangedwhileStates.CreatingHandleis set. Autocomplete initialization proceeds afterward as part of the existing handle-creation flow.Customer Impact
Regression?
Risk
Screenshots
Before
Run the attached application, on a non-system-DPI monitor, click the button to reproduce the crash.
TestComboBox.zip
devenv_BJDIKfNUlw.mp4
After
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow