Skip to content

Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR#130270

Merged
AaronRobinsonMSFT merged 18 commits into
mainfrom
copilot/fix-unmanagedcallersonly-attribute-issue
Jul 8, 2026
Merged

Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR#130270
AaronRobinsonMSFT merged 18 commits into
mainfrom
copilot/fix-unmanagedcallersonly-attribute-issue

Conversation

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

CoreCLR rejected [UnmanagedCallersOnly] attributes containing the newer AssociatedSourceType named argument, throwing META_E_CA_UNKNOWN_ARGUMENT when setting up unmanaged callbacks. Assemblies valid for NativeAOT could therefore fail under CoreCLR.

  • Runtime

    • Accept AssociatedSourceType in CoreCLR’s hand-written UnmanagedCallersOnlyAttribute parser.
    • Parse and ignore the value, matching the property’s NativeAOT-only semantics.
  • Regression coverage

    • Add a CoreCLR interop test for an unmanaged function pointer call to a method annotated with:
      [UnmanagedCallersOnly(AssociatedSourceType = typeof(UnmanagedCallersOnlyBasicTest))]

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 6, 2026 23:55
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 00:01
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 00:03
Copilot AI changed the title [WIP] Fix CoreCLR rejection of [UnmanagedCallersOnly] with AssociatedSourceType Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR Jul 7, 2026
Copilot AI requested a review from MichalStrehovsky July 7, 2026 00:04
@teo-tsirpanis teo-tsirpanis added area-VM-coreclr and removed area-Infrastructure-coreclr Only use for closed issues labels Jul 7, 2026
@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.

@MichalStrehovsky

Copy link
Copy Markdown
Member

@copilot same problem with mono: * Assertion at /__w/1/s/src/mono/mono/metadata/marshal.c:3478, condition `is_ok (error)' not met, function:mono_marshal_set_callconv_from_unmanaged_callers_only_attribute, Binary format of the specified custom attribute was invalid. assembly: type:UnmanagedCallersOnlyBasicTest member:(null)

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 01:43
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 12:26

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot undo changes in marshal.c that are not strictly necessary for the bugfix

Addressed in 7ea546a. The marshal.c diff against main now only keeps the image-context change needed for the bug fix and restores the unrelated assertion/warning/comment/style edits.

@MichalStrehovsky

Copy link
Copy Markdown
Member

@AaronRobinsonMSFT @elinor-fung could one of you have a look please? This fixes #130245 that macios repo hit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates CoreCLR’s UnmanagedCallersOnlyAttribute named-argument parsing to recognize the newer AssociatedSourceType named argument (and ignore it), preventing attribute parsing failures when consuming assemblies that include that argument. It also adds coverage and aligns Mono’s custom-attribute decoding to use the correct image when decoding the attribute blob.

Changes:

  • CoreCLR: Extend the known named-argument set for UnmanagedCallersOnlyAttribute to include AssociatedSourceType so parsing doesn’t fail on unknown named arguments.
  • Tests: Add an interop regression test using [UnmanagedCallersOnly(AssociatedSourceType = typeof(...))].
  • Mono: Decode UnmanagedCallersOnlyAttribute named args using the method’s defining image rather than corlib, to avoid decode failures when named args reference types outside corlib.

Reviewed changes

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

File Description
src/coreclr/vm/callconvbuilder.cpp Adds AssociatedSourceType to the recognized named args for UnmanagedCallersOnlyAttribute parsing.
src/tests/Interop/UnmanagedCallersOnlyBasic/UnmanagedCallersOnlyBasicTest.cs Adds a new UnmanagedCallersOnly method and a regression test for AssociatedSourceType.
src/mono/mono/metadata/marshal.c Switches attribute-blob decode context to the method’s image to correctly resolve named-arg types.

Comment thread src/tests/Interop/UnmanagedCallersOnlyBasic/UnmanagedCallersOnlyBasicTest.cs Outdated
Comment thread src/tests/Interop/UnmanagedCallersOnlyBasic/UnmanagedCallersOnlyBasicTest.cs Outdated
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 8, 2026 05:50
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 8, 2026 05:56
Copilot AI requested a review from MichalStrehovsky July 8, 2026 05:57
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit ac03213 into main Jul 8, 2026
147 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the copilot/fix-unmanagedcallersonly-attribute-issue branch July 8, 2026 15:48
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

CoreCLR rejects [UnmanagedCallersOnly] with the AssociatedSourceType named argument (0x801311C4)

5 participants