Skip to content

GeneratedComInterface relies on undefined QueryInterface behavior #129181

@dongle-the-gadget

Description

@dongle-the-gadget

Description

From official documentation about COM interface inheritance, there's no rule that says "if QI to B succeeds and B inherits from A, then QI to A must succeed."

However, any attempts to call methods located in interface A will result in a QueryInterface to A. The chain goes something like this:

  • User has COM object of interface B, which inherits from A.
  • User calls A.SomeMethod()
  • SomeMethod() calls IUnmanagedVirtualMethodTableProvider.GetVirtualMethodTableInfoForKey
  • ComObject.GetVirtualMethodTableInfoForKey calls LookUpVTableInfo which performs QueryInterface.

In effect, this means GeneratedComInterface relies on undefined QueryInterface behavior

Reproduction Steps

[GeneratedComInterface]
interface A
{
     void Method();
}

[GeneratedComInterface]
interface B : A;

StrategyBasedComWrappers comWrappers = new();
B b = (B)comWrappers.GetOrCreateObjectForComInstance(...);
b.Method();

Expected behavior

b.Method() runs successfully in all spec-compliant implementations of B.

Actual behavior

Potential System.InvalidCastException at b.Method(), even if the native object implementing B is compliant with COM specifications.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

Apparently, this QI behavior is present in Shell (microsoft/CsWin32#1716) and DirectComposition APIs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions