Skip to content

Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR#130270

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

Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR#130270
MichalStrehovsky with Copilot wants to merge 10 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 01:45
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:48

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@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_onl...

Addressed for Mono in baec198. The Mono path now parses the UnmanagedCallersOnly custom attribute blob directly for CallConvs and skips other named arguments such as AssociatedSourceType; the Mono-flavored UnmanagedCallersOnlyBasicTest passes locally.

@MichalStrehovsky

Copy link
Copy Markdown
Member

@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 issue with the extra property only? I don't want 250 lines of new code for something that was handled by 12 lines. keep the diff against main branch minimal.

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: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
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