Skip to content

Move IDispatch helpers into IDispatchHelpers.cs#126074

Merged
AaronRobinsonMSFT merged 6 commits intomainfrom
copilot/move-idispatch-helpers
Mar 27, 2026
Merged

Move IDispatch helpers into IDispatchHelpers.cs#126074
AaronRobinsonMSFT merged 6 commits intomainfrom
copilot/move-idispatch-helpers

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

Cherry-picks am11@ae7563a (author: Adeel Mujahid / am11) which converts MethodDescCallSite to UCO in DispatchInfo, then moves all IDispatch helper methods into their own file.

Changes

  • Cherry-picked commit ae7563a from am11/runtime with author preserved (Adeel Mujahid)
  • Created src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/IDispatchHelpers.cs as a standalone internal static class IDispatchHelpers in the System.Runtime.InteropServices namespace, containing all IDispatch-related helpers:
    • Existing helpers moved from StubHelpers.cs: DispatchExPropertyCanRead/DispatchExPropertyCanWrite constants and GetDispatchExPropertyFlags
    • New helpers: GetDispatchParameterInfoName, GetDispatchMemberInfoName, GetDispatchMemberInfoType, HasDispatchCustomAttribute, GetDispatchMemberParameters, GetDispatchPropertyTokenAndModule, GetDispatchPropertyAccessor, GetDispatchFieldValue, SetDispatchFieldValue, GetDispatchPropertyValue, SetDispatchPropertyValue, InvokeDispatchMethodInfo, InvokeDispatchReflectMember, GetDispatchProperties, GetDispatchFields, GetDispatchMethods, GetDispatchInnerException
  • Removed those methods from StubHelpers.cs
  • Added IDispatchHelpers.cs to System.Private.CoreLib.csproj under the FeatureCominterop condition group (no #if FEATURE_COMINTEROP inside the file itself, as conditional compilation is handled by the project file)
  • Updated corelib.h to define a new IDISPATCHHELPERS class entry (mapped to System.Runtime.InteropServices.IDispatchHelpers) and moved all dispatch-related DEFINE_METHOD registrations from STUBHELPERS to IDISPATCHHELPERS
  • Updated dispatchinfo.cpp and stdinterfaces.cpp to use METHOD__IDISPATCHHELPERS__* method references instead of METHOD__STUBHELPERS__* for all IDispatch methods
  • Consolidated all nested and consecutive GCPROTECT_BEGIN / GCPROTECT_END pairs in dispatchinfo.cpp into single struct-based GCPROTECT_BEGIN blocks using the standard anonymous-struct gc pattern
  • In GetMemberProps() and SetUpParamMarshalerInfo(), replaced the GetDispatchMethodDesc and GetDispatchFieldDesc managed callbacks with direct native casts to REFLECTMETHODREF/REFLECTFIELDREF and calls to GetMethod()/GetField() — eliminating those two callbacks entirely
  • Merged the GetDispatchPropertyToken and GetDispatchPropertyModule managed callbacks into a single GetDispatchPropertyTokenAndModule callback that returns both values in one call
  • Changed GetDispatchMemberInfoType to return int directly (like GetDispatchExPropertyFlags) and updated its call site to use InvokeThrowing_Ret<INT32>
  • Removed all [SupportedOSPlatform("windows")] annotations from IDispatchHelpers.cs and the now-unused using System.Runtime.Versioning;
  • Cleaned up unused metasig entries in metasig.h (SM_PtrMethodBase_PtrIntPtr_PtrException_RetVoid, SM_PtrFieldInfo_PtrIntPtr_PtrException_RetVoid, SM_PtrPropertyInfo_PtrModule_PtrException_RetVoid, SM_PtrMember_PtrInt_PtrException_RetVoid, SM_PtrPropertyInfo_PtrInt_PtrException_RetVoid) and added replacements (SM_PtrMember_PtrException_RetInt, SM_PtrPropertyInfo_PtrInt_PtrModule_PtrException_RetVoid)

Note

This PR was created with AI assistance (GitHub Copilot).


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copilot AI requested a review from jkotas March 25, 2026 05:08
@jkotas jkotas marked this pull request as ready for review March 25, 2026 05:21
Copilot AI review requested due to automatic review settings March 25, 2026 05:21
Copilot AI requested a review from jkotas March 25, 2026 05:24
Copy link
Copy Markdown
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 refactors CoreCLR COM interop dispatch support by moving IDispatch-related managed helpers out of StubHelpers into a dedicated System.Runtime.InteropServices.IDispatchHelpers type, and updates the VM to call these helpers via UnmanagedCallersOnlyCaller.

Changes:

  • Introduces IDispatchHelpers.cs and migrates all IDispatch helper entrypoints from StubHelpers to the new type.
  • Updates CoreCLR VM call sites (e.g., dispatchinfo.cpp, stdinterfaces.cpp) to use METHOD__IDISPATCHHELPERS__* instead of METHOD__STUBHELPERS__*.
  • Extends corelib.h and metasig.h to register the new class and required metasigs; updates CoreLib project file inclusion under FeatureCominterop.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/coreclr/vm/stdinterfaces.cpp Switches DispatchEx helper call to IDISPATCHHELPERS entrypoint.
src/coreclr/vm/metasig.h Adds metasigs needed for new UCO helper signatures.
src/coreclr/vm/dispatchinfo.cpp Replaces MethodDescCallSite usage with UnmanagedCallersOnlyCaller calls into IDispatchHelpers.
src/coreclr/vm/corelib.h Registers new IDISPATCHHELPERS class and maps VM method IDs to the new managed helpers.
src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs Removes IDispatch helper(s) and adds RequiresUnsafe annotations to some UCO methods.
src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/IDispatchHelpers.cs Adds new managed helper type with [UnmanagedCallersOnly] entrypoints for IDispatch interop.
src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj Includes IDispatchHelpers.cs under FeatureCominterop.

Comment thread src/coreclr/vm/metasig.h Outdated
Comment thread src/coreclr/vm/dispatchinfo.cpp Outdated
Comment thread src/coreclr/vm/dispatchinfo.cpp Outdated
Comment thread src/coreclr/vm/dispatchinfo.cpp Outdated
Comment thread src/coreclr/vm/dispatchinfo.cpp Outdated
Comment thread src/coreclr/vm/dispatchinfo.cpp Outdated
Comment thread src/coreclr/vm/dispatchinfo.cpp Outdated
…rectly, merge property callbacks, use InvokeThrowing_Ret, remove SupportedOSPlatform annotations

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/b1a9ba44-d8f2-4fb0-984b-b4e0fda837a2
Copy link
Copy Markdown
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

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

Looks good, I think it would need to resolve conflicts after @AaronRobinsonMSFT's PR is merged.

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Mar 26, 2026

/ba-g known issue dotnet/dnceng#6473 (no space left on device), not getting matched for some reason

@huoyaoyuan
Copy link
Copy Markdown
Member

I was postponing DispatchInfo with #124423. The invokers could be moved to managed as well and reduce the interop boundary.

@am11
Copy link
Copy Markdown
Member

am11 commented Mar 27, 2026

The goal here is to get rid of MethodDescCallSite and this PR is dropping 31 of 58 remaining usages. Complete managed port can be done separately.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 48e89ca into main Mar 27, 2026
105 of 109 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the copilot/move-idispatch-helpers branch March 27, 2026 17:23
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants