Skip to content

Convert more COM interop MethodDescCallSite to UnmanagedCallersOnly (UCO)#125849

Open
Copilot wants to merge 5 commits intomainfrom
copilot/address-pending-feedback
Open

Convert more COM interop MethodDescCallSite to UnmanagedCallersOnly (UCO)#125849
Copilot wants to merge 5 commits intomainfrom
copilot/address-pending-feedback

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

Continues the COM interop UCO migration (group 5), converting three MethodDescCallSite call sites to the UCO pattern and removing associated dead code. Addresses all pending feedback from #125508.

Changes

New UCO helpers in StubHelpers.cs

  • GetDispatchExPropertyFlags – replaces two MethodDescCallSite calls for PropertyInfo.CanRead/CanWrite in DispatchEx_GetMemberProperties
  • CallICustomQueryInterface – replaces the InvokeICustomQueryInterfaceGetInterface_CallBack struct/callback pattern; returns int directly (uses InvokeThrowing_Ret)
  • InvokeConnectionPointProviderMethod – replaces two MethodDescCallSite calls in ConnectionPoint::InvokeProviderMethod; always uses nint for the delegate ctor (drops useUIntPtrCtor bool per feedback)
  • Added [RequiresUnsafe] to the existing GetIEnumeratorToEnumVariantMarshaler UCO overload for consistency

Feedback addressed from #125508

  • INVOKE_CONNECTION_POINT_PROVIDER_METHOD registered as NoSig in corelib.h (has unmanaged fn-ptr params — encoding in metasig not worth the pain)
  • CallICustomQueryInterface uses InvokeThrowing_Ret<INT32> and passes ppUnkOut directly — no local copy needed
  • useUIntPtrCtor bool removed — delegate ctors always have an (object, nint) overload

Dead code removed

  • InvokeICustomQueryInterfaceGetInterface_CallBack + arg struct in comcallablewrapper.cpp
  • GetICustomQueryInterfaceGetInterfaceMD / m_pICustomQueryInterfaceGetInterfaceMD from ComCallWrapperTemplate
  • m_ohDelegate union field and GetOHDelegate/SetOHDelegate/GetObjCreateDelegate/SetObjCreateDelegate from EEClass/MethodTableSetObjCreateDelegate had no callers; the delegate-based CreateAggregatedInstance path was effectively dead

Converts COM interop code from MethodDescCallSite to UnmanagedCallersOnly
(UCO) pattern for three sites:

1. DispatchEx_GetMemberProperties (Property case): replaces two
   MethodDescCallSite invocations (for CanRead/CanWrite) with a single
   UCO helper GetDispatchExPropertyFlags in StubHelpers.

2. ICustomQueryInterface.GetInterface: replaces the callback struct
   pattern with a UCO helper CallICustomQueryInterface. Also removes
   the cached MethodDesc field m_pICustomQueryInterfaceGetInterfaceMD
   from ComCallWrapperTemplate.

3. ConnectionPoint.InvokeProviderMethod: replaces MethodDescCallSite
   calls for delegate construction and provider invocation with a
   single UCO helper InvokeConnectionPointProviderMethod. Removes the
   UIntPtr ctor fallback path (addressing pending feedback).

Also removes the m_ohDelegate field and related methods
(GetOHDelegate/SetOHDelegate/GetObjCreateDelegate/SetObjCreateDelegate)
from EEClass/MethodTable since the delegate-based COM object creation
callback feature in CreateAggregatedInstance is removed.

Adds [RequiresUnsafe] to GetIEnumeratorToEnumVariantMarshaler UCO
overload to be consistent with the new UCO methods.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas marked this pull request as ready for review March 20, 2026 20:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the CoreCLR COM interop migration away from MethodDescCallSite toward the UnmanagedCallersOnly (UCO) reverse-P/Invoke calling pattern, and removes now-dead COM interop callback/delegate infrastructure in the VM.

Changes:

  • Added new UCO helpers in StubHelpers.cs and updated native call sites to use UnmanagedCallersOnlyCaller.
  • Converted COM interop call paths in stdinterfaces.cpp, comconnectionpoints.cpp, and comcallablewrapper.cpp from MethodDescCallSite to UCO-based helpers.
  • Removed dead COM interop delegate/callback code paths and related cached fields/helpers in VM types.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/coreclr/vm/stdinterfaces.cpp Uses UCO helper to query PropertyInfo.CanRead/CanWrite flags instead of two MethodDescCallSite calls.
src/coreclr/vm/runtimecallablewrapper.cpp Removes unused delegate-based aggregated COM instance creation path and related logic.
src/coreclr/vm/methodtable.h Removes delegate-handle-related APIs from MethodTable.
src/coreclr/vm/methodtable.cpp Removes implementations for COM object-creation delegate storage/retrieval.
src/coreclr/vm/metasig.h Adds COM-interp UCO metasig definitions for new StubHelpers methods.
src/coreclr/vm/corelib.h Registers new StubHelpers methods (including a NoSig entry).
src/coreclr/vm/comconnectionpoints.cpp Uses a single UCO helper to construct delegate + invoke provider method.
src/coreclr/vm/comcallablewrapper.h Removes cached ICustomQueryInterface.GetInterface MethodDesc field/API.
src/coreclr/vm/comcallablewrapper.cpp Replaces callback/cached-MD pattern with UCO helper that calls ICustomQueryInterface.GetInterface.
src/coreclr/vm/class.h Removes now-dead delegate handle storage from EEClass COM interop union.
src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs Adds UCO helpers for DispatchEx property flags, ICustomQueryInterface, and connection point invocation.

Comment on lines +1890 to 1894
enum : INT32
{
ObjToArgSlot(MemberInfoObj)
DispatchExPropertyCanRead = 1,
DispatchExPropertyCanWrite = 2,
};
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The DispatchExPropertyCanRead/DispatchExPropertyCanWrite bit values are duplicated here and in StubHelpers.GetDispatchExPropertyFlags. Consider centralizing them (e.g., a shared header/enum or a single source of truth) or at least adding a note/assertion to keep the native and managed definitions in sync to prevent silent flag drift.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants