Skip to content

Convert CustomMarshalerInfo GetInstance to UnmanagedCallersOnly#124440

Open
AaronRobinsonMSFT wants to merge 2 commits intodotnet:mainfrom
AaronRobinsonMSFT:uco-custom-marshaler-getinstance
Open

Convert CustomMarshalerInfo GetInstance to UnmanagedCallersOnly#124440
AaronRobinsonMSFT wants to merge 2 commits intodotnet:mainfrom
AaronRobinsonMSFT:uco-custom-marshaler-getinstance

Conversation

@AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Feb 15, 2026

Converts the last Priority 1 item from #123864 — replacing MethodDescCallSite/CallDescrWorker with UnmanagedCallersOnly reverse P/Invoke for the GetInstance call in CustomMarshalerInfo::CustomMarshalerInfo.

Changes

  • Add MngdRefCustomMarshaler.GetCustomMarshalerInstance UCO wrapper
  • Add metasig and corelib.h entries for the new UCO method

Copilot AI review requested due to automatic review settings February 15, 2026 05:52
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 11.0.0 milestone Feb 15, 2026
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 converts the CustomMarshalerInfo GetInstance call from the legacy MethodDescCallSite/CallDescrWorker infrastructure to the more efficient UnmanagedCallersOnly reverse P/Invoke pattern, completing the last Priority 1 item from issue #123864.

Changes:

  • Added GetCustomMarshalerInstance UnmanagedCallersOnly wrapper in MngdRefCustomMarshaler that converts MethodDesc pointer to MethodBase, invokes GetInstance via reflection, and validates non-null return
  • Moved null-return validation from native to managed code using the existing managed resource string SR.CustomMarshaler_NullReturnForGetInstance
  • Removed unused native resource strings IDS_EE_NOCUSTOMMARSHALER from resource.h and mscorrc.rc

Reviewed changes

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

Show a summary per file
File Description
src/coreclr/vm/metasig.h Added signature definition for new UCO method: IntPtr, byte*, int, object*, Exception* parameters
src/coreclr/vm/corelib.h Added DEFINE_METHOD entry for GetCustomMarshalerInstance
src/coreclr/vm/custommarshalerinfo.cpp Replaced MethodDescCallSite with UnmanagedCallersOnlyCaller, removed string creation, updated comment to reflect managed Invoke usage
src/coreclr/dlls/mscorrc/resource.h Removed unused IDS_EE_NOCUSTOMMARSHALER resource ID
src/coreclr/dlls/mscorrc/mscorrc.rc Removed unused native error message string
src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs Implemented GetCustomMarshalerInstance UCO method with MethodDesc-to-MethodBase conversion, UTF-8 string decoding, reflection invoke, and null validation

@AaronRobinsonMSFT AaronRobinsonMSFT force-pushed the uco-custom-marshaler-getinstance branch 2 times, most recently from 9c8b724 to 171c3c7 Compare February 15, 2026 06:16
Copilot AI review requested due to automatic review settings February 15, 2026 06:16
@AaronRobinsonMSFT AaronRobinsonMSFT force-pushed the uco-custom-marshaler-getinstance branch 2 times, most recently from e615ba7 to 0618885 Compare February 15, 2026 06:22
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Replace MethodDescCallSite/CallDescrWorker with UnmanagedCallersOnly
reverse P/Invoke for the GetInstance call in CustomMarshalerInfo.

- Add MngdRefCustomMarshaler.GetCustomMarshalerInstance UCO wrapper
  that takes a MethodTable pointer and raw UTF-8 cookie bytes, finds
  GetInstance via managed reflection, invokes it, and validates the
  result is non-null
- Move FindGetInstanceMethod logic entirely into managed code,
  eliminating the native method lookup, generic instantiation stub
  handling, and MetaSig::EnsureSigValueTypesLoaded
- Move null-return and missing-method validation from native to managed
  using existing SR resource strings
- Remove unused IDS_EE_NOCUSTOMMARSHALER and IDS_EE_GETINSTANCENOTIMPL
  from resource.h and mscorrc.rc
- Remove unused gsig_SM_Str_RetICustomMarshaler metasig entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AaronRobinsonMSFT AaronRobinsonMSFT force-pushed the uco-custom-marshaler-getinstance branch from 0618885 to e358b8a Compare February 15, 2026 16:28
Copilot AI review requested due to automatic review settings February 17, 2026 05:50
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants