Skip to content

Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR#130270

Draft
MichalStrehovsky with Copilot wants to merge 15 commits into
mainfrom
copilot/fix-unmanagedcallersonly-attribute-issue
Draft

Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR#130270
MichalStrehovsky with Copilot wants to merge 15 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 removed the request for review from Copilot July 7, 2026 04:25
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 04:27
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 04:29
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 04:31
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 04:33
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 04:35
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 04:37

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot this is a lot of new code in Mono. we only need this to support this narrow path with the existing limitations (e.g. multiple callconvs do not work). can you address the specific issu...

Addressed in 1ae3051. The broad Mono custom-attribute parser rewrite was removed; the Mono diff now only skips the narrow AssociatedSourceType-only attribute blob before falling back to the existing CallConvs decoder and its existing limitations.

@MichalStrehovsky

Copy link
Copy Markdown
Member

@copilot is the bug on the Mono side in mono_reflection_create_custom_attr_data_args_noalloc? fix the bug there. you keep creating workarounds in the past few commits instead of fixing the bug.

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

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot is the bug on the Mono side in mono_reflection_create_custom_attr_data_args_noalloc? fix the bug there. you keep creating workarounds in the past few commits instead of fixing the bug.

Addressed in af7862f. I removed the AssociatedSourceType blob workaround and fixed the decode path to call mono_reflection_create_custom_attr_data_args_noalloc with the attributed method's image, so System.Type named arguments resolve in the correct metadata context while preserving the existing CallConvs handling.

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.

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

3 participants