Skip to content

[Accessibility] Fixing ComboBoxAccessibleObject issue when Narrator and Inspect don't respond - #3524

Merged
RussKie merged 1 commit into
dotnet:masterfrom
vladimir-krestov:dev/v-vlkres/3452_Fixing_ComboBoxAccessibleObject
Jul 6, 2020
Merged

RussKie merged 1 commit into
dotnet:masterfrom
vladimir-krestov:dev/v-vlkres/3452_Fixing_ComboBoxAccessibleObject

Conversation

@vladimir-krestov

@vladimir-krestov vladimir-krestov commented Jun 29, 2020 •

Copy link
Copy Markdown
Contributor

Fixes #3452

Proposed changes

  • Just remove [ComImport] attribute

Customer Impact

  • ComboBox doesn't break Narrator and Inspect

Regression?

Risk

  • Minimal

Screenshots

Before

  • Inspect doesn't response after selecting ComboBox editing control
    bug

After

  • ComboBox AccessibleObject works well
    Fixed

Test methodology

  • Manual testing
  • CTI

Accessibility testing

  • Using Narrator and Inspect

Test environment(s)

  • Microsoft Windows [Version 10.0.18363.900]
  • .Net Version: 5.0.0-preview.8.20326.9
Microsoft Reviewers: Open in CodeFlow

@vladimir-krestov
vladimir-krestov requested a review from a team as a code owner June 29, 2020 18:47
@vladimir-krestov

Copy link
Copy Markdown
Contributor Author

This bug was added when 423b2bc was merged.
The bug is not reproduced if to remove [ComImport] attribute.

@hughbe, @JeremyKuhne
Why do we need this attribute?
Why removing the attribute fixes the issue of ComboBox?

@hughbe

hughbe commented Jun 29, 2020

Copy link
Copy Markdown
Contributor

I’m sorry I don’t know if this right? Can’t understand why removing ComImport would fix things... this is a com import

@JeremyKuhne

Copy link
Copy Markdown
Member

@AaronRobinsonMSFT is there perhaps something funky with putting [ComImport] on both a base and a derived interface?

        [ComImport]
        [Guid("D6DD68D1-86FD-4332-8666-9ABEDEA2D24C")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IRawElementProviderSimple {}

        [ComImport] // <-- broke things??
        [Guid("1d5df27c-8947-4425-b8d9-79787bb460b8")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IRawElementProviderHwndOverride : IRawElementProviderSimple {}

@AaronRobinsonMSFT

AaronRobinsonMSFT commented Jun 29, 2020 •

Copy link
Copy Markdown
Member

something funky with putting [ComImport] on both a base and a derived interface?

Not that I know of. However, IRawElementProviderHwndOverride doesn't inherit from IRawElementProviderSimple - see IRawElementProviderHwndOverride. This is also observed in the IDL:

MIDL_INTERFACE("1d5df27c-8947-4425-b8d9-79787bb460b8")
IRawElementProviderHwndOverride : public IUnknown
{
public:
    virtual HRESULT STDMETHODCALLTYPE GetOverrideProviderForHwnd( 
        /* [in] */ __RPC__in HWND hwnd,
        /* [retval][out] */ __RPC__deref_out_opt IRawElementProviderSimple **pRetVal) = 0;
    
};

Even if it was, the inheriting interface needs to be declared in the derived type. Can't find a good link, but in general it would be something like:

interface IFoo
{
   void Bar();
}

interface IFoo2 : IFoo
{
    new void Bar();

    void Baz();
}

@AaronRobinsonMSFT

AaronRobinsonMSFT commented Jun 29, 2020 •

Copy link
Copy Markdown
Member

Sigh... I just looked at IRawElementProviderHwndOverride. That isn't correct, but I don't think it would be easy to change now. I don't see why this would impact the system at all, but I could see it messing with the runtime if the type is defined to inherit in some way and it doesn't actually. Especially if the type is being consumed from native.

@hughbe

hughbe commented Jun 29, 2020

Copy link
Copy Markdown
Contributor

Cref #3231 which should fux

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

@hughbe We need to be careful about changing this type. This is a breaking change from the .NET side of things even if it is wrong with respect to the actual COM types. @RussKie and @JeremyKuhne What are your thoughts on this breaking change?

I have no opinion either way. Let's just make sure we understand the user impact.

@JeremyKuhne

Copy link
Copy Markdown
Member

However, IRawElementProviderHwndOverride doesn't inherit from IRawElementProviderSimple

Ugh, sorry I missed this. :)

What are your thoughts on this breaking change?

As we've documented it as deriving we should probably leave it that way. We can just comment fully as to the weirdness with this particular instance in the code so we handle it more carefully in the future.

@RussKie

RussKie commented Jun 30, 2020

Copy link
Copy Markdown
Contributor

If the accessibility tools continue to function (such as Narrator and Accessibility Insights) I think we can take the change.

/cc: @merriemcgaw

@hughbe

hughbe commented Jun 30, 2020

Copy link
Copy Markdown
Contributor

@hughbe We need to be careful about changing this type. This is a breaking change from the .NET side of things even if it is wrong with respect to the actual COM types. @RussKie and @JeremyKuhne What are your thoughts on this breaking change?

Is this a breaking change? AFAICT it’s an internal interop type

@RussKie

RussKie commented Jun 30, 2020

Copy link
Copy Markdown
Contributor

Yes, you're right - all these types live in internal static partial class UiaCore, so they are not directly exposed to our consumers, only indirectly via Control.AccessibilityObject properties IIUC.

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

If that is true, where is the type described by the referenced documentation above?

@RussKie

RussKie commented Jul 1, 2020

Copy link
Copy Markdown
Contributor

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

I believe these docs are from WPF:

Ah. Okay. Then this seems like changing the definition for WinForms is appropriate since it is an internal implementation detail.

@merriemcgaw merriemcgaw changed the title [Accessibility] Fixing ComboBoxAccessibleObject issue when Narrator and Inspect don't response [Accessibility] Fixing ComboBoxAccessibleObject issue when Narrator and Inspect don't respond Jul 2, 2020
@vladimir-krestov vladimir-krestov added waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) and removed waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) labels Jul 3, 2020
@vladimir-krestov

Copy link
Copy Markdown
Contributor Author

Testers approved these changes ✔️
Inspect crashes without the fix and works well if to remove [ComImport]

@RussKie
RussKie merged commit 3cb43e7 into dotnet:master Jul 6, 2020
@ghost ghost added this to the 5.0 Preview8 milestone Jul 6, 2020
Comment on lines 16 to 17
/// </summary>
[ComImport]
[Guid("1d5df27c-8947-4425-b8d9-79787bb460b8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

@weltkante weltkante Jul 8, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RussKie @JeremyKuhne

I don't think this is right, if ComImport is removed the others should also be removed for consistency (i.e. make it a purely managed interface), otherwise you risk the dotnet runtime or tooling doing the wrong thing (you don't own the interface declaration, so it must be import or nothing to my knowledge, I think all other code paths in the runtime either disable COM interop or are related to ComVisible in various variants and thats a dangerous path to go down when you are not the owner)

I think we switched all projects to [assembly: ComVisible(false)] so the default behavior of not having ComImport should be not exposing the interface through COM interop? Did anyone test if this interface is still used by Narrator/Inspect when making it purely managed? For what its worth you may just have disabled the interface for COM interop, meaning its equivalent of not implementing it in the first place.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. [ComImport] itself doesn't expose it, it just generates a RCW/CCW if you pass the implementing class through interop.

From what I read we should remove the derivation, not the [ComImport] if we're exposing the implementing objects in any way to native. Or am I missing something?

@weltkante weltkante Jul 8, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally just uncomfortable with removing [ComImport] without removing the GUID referring to an interface you don't own, considering the default if no [ComImport] is given would be an implicit [ComVisible(true)] meaning you claim that you own the interface.

That should not happen since we specified the assembly-level ComVisible(false) attribute but personally I don't understand all the code paths, a lot of logic just defaults to assuming non-import interfaces means the assembly owns the declaration. Any such decision must be avoided since it would be wrong.

To my understanding with this PR the [Guid]/[InterfaceType] attributes are now no longer having any effect so can and should be removed together with [ComImport]. If I'm missing something and the other two attributes are still doing something I'd like to know what happens, because I suspect it might just superficially work but might be wrong when looking at it in detail.

TLDR: to me it looks like this is now a plain managed interface and not performing any interop purpose besides forcing a base interface implementation, so the other two attributes should be removed together with ComImport to prevent mistaking the interface for something it isn't

@Tanya-Solyanik

Copy link
Copy Markdown
Contributor

I'm not even sure that this fix is working properly, I can't click around items in the combobox drop downs in our test application when inspect is running, at some point inspect hangs.

@merriemcgaw

Copy link
Copy Markdown
Contributor

@RussKie to keep an eye on this one too.

@Tanya-Solyanik

Copy link
Copy Markdown
Contributor

@JeremyKuhne, @AaronRobinsonMSFT -

From what I read we should remove the derivation, not the [ComImport] if we're exposing the implementing objects in any way to native. Or am I missing something?

I experimented like this:

  1. removed derivation and kept [ComImport], => inspect does not work
  2. keep derivation+ remove [ComImport] => inspect works
  3. remove derivation and remove [ComImport] => inspect works

These results don't make sense to me. I think we are covering up a bigger issue here. Do you have any suggestions?

@AaronRobinsonMSFT

AaronRobinsonMSFT commented Jul 16, 2020 •

Copy link
Copy Markdown
Member

@Tanya-Solyanik @hughbe @JeremyKuhne I truthfully am unclear on what is going on here. All I noted was the type definition isn't correct. Can someone create a minimal example that I can debug?

@vladimir-krestov

Copy link
Copy Markdown
Contributor Author

@AaronRobinsonMSFT, I use the internal test forms in our project. ../tests/integration/WinformsControlsTest

It's comfortable to make changes in the code and just run the test project without moving any dlls.
Run the test project and click ComboBoxes. You can use it as a minimal example that you can debug.

image

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

@vladimir-krestov Unfortunately I can't really use Narrator so am having a tough time reproducing this issue. I am on Remote Desktop from a mac and that doesn't seem to work with Narrator. Any way we could reduce the issue to some other approach? I will try a few other things as well.

@vladimir-krestov

Copy link
Copy Markdown
Contributor Author

@AaronRobinsonMSFT, can you use Inspect?

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

@vladimir-krestov I stand corrected. I am able to use Narrator - was a setting on the macOS RDP client. On the above example, I am able to hear it say "ComboBox". Can we elaborate on what I should or shouldn't hear?

@vladimir-krestov

Copy link
Copy Markdown
Contributor Author

@AaronRobinsonMSFT, Narrator and Inspect don't respond if to click to an edit field of a ComboBox.
After deleting [ComImport] attribute everything works well. If to return this attribute your Inspect will crash.
And we don't know is my fix correct? Or it is a latent bigger issue.

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

I am also able to hear the Narrator enumerate each element in the ComboBox when expanded as well as state the count.

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

This isn't working at all. In fact by removing the ComImport the IRawElementProviderHwndOverride type is never queried by Narrator and therefore GetOverrideProviderForHwnd is never called - which is why it "works". This is an area I am very unfamiliar with but there is something wrong with how IRawElementProviderHwndOverride is used and it's implementation is a bit convoluted.

Someone from WinForms or with far more experience/knowledge of the Accessibility API needs to actually debug the implementation instead of just making sure it doesn't crash. I can help out, but this doesn't seem like a specific COM issue since the interface itself appears very straight forward. If someone can point to a specific COM interop issue I am more than willing to investigate but the current issue is simply using this Accessibility interface in general.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Accessibility] ComboBox control causes Narrator and Inspect to stop responding

8 participants