Skip to content

Fix InvalidCastException in ComboBoxAutomationPeer / forward Scroll to ItemsControl #10877

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented May 26, 2025

Description

Fixes InvalidCastException in ComboBoxAutomationPeer which occurs because ComboBoxAutomationPeer nor its parents implement IScrollProvider directly and hence the whole code block is just wrong as it will never work.

We should use the ItemsControlAutomationPeer implementation to provide the interface via ScrollHost / ScrollViewer, which should be done only if the drop-down is open. See https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-supportcomboboxcontroltype.

Reproduction steps are easy:

  1. Put a ComboBox onto your window with some items
  2. Open the app, optionally enable native managed boundary exceptions in VS
  3. Start Narrator or any other UIA app, and watch the exceptions flow

Customer Impact

Better performance and correct interface when the dropdown is open, improved accessibility.

Regression

Yes, this was introduced in #1278, guess the comment was misunderstood by the implementor and nobody bothered to check/test during review.

Testing

Local build, exploring the automation tree, ensuring the exception no longer happens.

Risk

Low.

@h3xds1nz h3xds1nz requested a review from a team as a code owner May 26, 2025 09:29
Copy link

codecov bot commented May 26, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 2.98819%. Comparing base (57fe8ac) to head (46bc68e).
Report is 10 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main     #10877          +/-   ##
===================================================
- Coverage   13.48885%   2.98819%   -10.50066%     
===================================================
  Files           3317       3319           +2     
  Lines         664749     664885         +136     
  Branches       74643      74673          +30     
===================================================
- Hits           89667      19868       -69799     
- Misses        572488     644836       +72348     
+ Partials        2594        181        -2413     
Flag Coverage Δ
Debug 2.98819% <0.00000%> (-10.50066%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant