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.
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
Awill result in aQueryInterfacetoA. The chain goes something like this:B, which inherits fromA.A.SomeMethod()SomeMethod()callsIUnmanagedVirtualMethodTableProvider.GetVirtualMethodTableInfoForKeyComObject.GetVirtualMethodTableInfoForKeycallsLookUpVTableInfowhich performsQueryInterface.In effect, this means
GeneratedComInterfacerelies on undefinedQueryInterfacebehaviorReproduction Steps
Expected behavior
b.Method()runs successfully in all spec-compliant implementations ofB.Actual behavior
Potential
System.InvalidCastExceptionatb.Method(), even if the native object implementingBis 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.