Skip to content

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

Merged
AaronRobinsonMSFT merged 8 commits intomainfrom
copilot/address-pending-feedback
Mar 24, 2026
Merged

Convert more COM interop MethodDescCallSite to UnmanagedCallersOnly (UCO)#125849
AaronRobinsonMSFT merged 8 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.

Description

New UCO helpers in StubHelpers.cs

  • GetDispatchExPropertyFlags – replaces two MethodDescCallSite calls for PropertyInfo.CanRead/CanWrite in DispatchEx_GetMemberProperties; returns int directly via InvokeThrowing_Ret at the callsite (no out-param)
  • CallICustomQueryInterface – replaces the InvokeICustomQueryInterfaceGetInterface_CallBack struct/callback pattern; returns int directly (uses InvokeThrowing_Ret)
  • InvokeConnectionPointProviderMethod – replaces two MethodDescCallSite calls in ConnectionPoint::InvokeProviderMethod; uses nint/UIntPtr ctor fallback for correctness; uses GetMultiCallableAddrOfCode() for the event target since it is stored for future invokes
  • Added [RequiresUnsafe] to the existing GetIEnumeratorToEnumVariantMarshaler UCO overload for consistency

Feedback addressed

  • 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
  • GetDispatchExPropertyFlags signature changed to return int directly; metasig (SM_PtrPropertyInfo_PtrException_RetInt) and corelib.h registration updated accordingly; callsite in stdinterfaces.cpp updated to use InvokeThrowing_Ret<INT32>
  • UIntPtr ctor fallback restored in ConnectionPoint::InvokeProviderMethod for correctness
  • Comment updated in comconnectionpoints.cpp to clarify why GetMultiCallableAddrOfCode() is used for the event target

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

⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

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.

Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Choose a reason for hiding this comment

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

Some minor nits. Otherwise, looks good when green.

…InvokeThrowing_Ret

Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/dde670ee-197d-4271-8596-d75d3cca3116
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 11.0.0 milestone Mar 23, 2026
@AaronRobinsonMSFT AaronRobinsonMSFT enabled auto-merge (squash) March 23, 2026 23:06
@jkotas
Copy link
Member

jkotas commented Mar 24, 2026

/ba-g timeouts

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 63e88d1 into main Mar 24, 2026
96 of 104 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the copilot/address-pending-feedback branch March 24, 2026 04:11
@am11
Copy link
Member

am11 commented Mar 24, 2026

@jkotas, it would be good to ask copilot to keep the author of original commit and add stuff on top.

am11@ae7563a has dispatchinfo conversions. I tested it last week but haven't retested after the cherry-pick (should be fine). Copilot can pick it and continue the next batch.

@jkotas
Copy link
Member

jkotas commented Mar 25, 2026

am11@ae7563a

Triggered copilot on it with explicit instruction to preserve the author name and some initial feedback, let's see how it does.

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.

5 participants