Ignore AssociatedSourceType on UnmanagedCallersOnly in CoreCLR#130270
Conversation
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
Tagging subscribers to this area: @agocke |
|
@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>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
@AaronRobinsonMSFT @elinor-fung could one of you have a look please? This fixes #130245 that macios repo hit. |
There was a problem hiding this comment.
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
UnmanagedCallersOnlyAttributeto includeAssociatedSourceTypeso parsing doesn’t fail on unknown named arguments. - Tests: Add an interop regression test using
[UnmanagedCallersOnly(AssociatedSourceType = typeof(...))]. - Mono: Decode
UnmanagedCallersOnlyAttributenamed args using the method’s defining image rather thancorlib, to avoid decode failures when named args reference types outsidecorlib.
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. |
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
CoreCLR rejected
[UnmanagedCallersOnly]attributes containing the newerAssociatedSourceTypenamed argument, throwingMETA_E_CA_UNKNOWN_ARGUMENTwhen setting up unmanaged callbacks. Assemblies valid for NativeAOT could therefore fail under CoreCLR.Runtime
AssociatedSourceTypein CoreCLR’s hand-writtenUnmanagedCallersOnlyAttributeparser.Regression coverage