From f4311a47aa1df5dd8d3962919ccb5e907a936644 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 17 Jun 2026 16:37:40 +0200 Subject: [PATCH] Preserve StubHelpers array marshalers in ILLink descriptor (#128027) Trimmed apps throw System.Security.VerificationException whenever they marshal an array of a non-blittable struct (e.g. via [MarshalAs(UnmanagedType.LPArray/ByValArray)] or Marshal.StructureToPtr). This breaks every net11.0-android Release build at startup, because Java.Interop's JNIEnvInit.Initialize marshals a JniNativeMethodRegistration[] LPArray before any user code runs; iOS/tvOS Release builds are affected too. The runtime's IL-stub generator references the array (element) marshalers by name from native code (CLASS__*_MARSHALER in src/coreclr/vm/corelib.h) and passes them as the TMarshaler type argument to ConvertArraySpaceToNative / FreeArrayContents, whose generic constraint requires the IArrayMarshaler static-abstract implementation. The trimmer cannot see these uses (the P/Invoke marshalling stub is generated at runtime by the VM), so it strips the static-virtual interface implementations and the constraint check fails at runtime. Preserve the always-present (non-COM-interop) StubHelpers marshalers in ILLink.Descriptors.Shared.xml. These entries were originally added by #128020 and removed by #128272 on the assumption the illink-side fix for #128120 was sufficient; it is not for the runtime-generated P/Invoke stub path, which has no managed reference for the trimmer to follow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/ILLink/ILLink.Descriptors.Shared.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.Shared.xml b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.Shared.xml index 0c7a6d7e6259fb..2695c5bead1170 100644 --- a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.Shared.xml +++ b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.Shared.xml @@ -9,6 +9,19 @@ + + + + + + + + + + + +