From 7880c6397015fded3e74af258c8cbf2ce4f3c094 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 May 2026 01:56:01 +0000 Subject: [PATCH 1/7] Initial plan From 06ac10b3b97c4bcc1bb370bd6628d4c2f12a5dd9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 May 2026 02:00:23 +0000 Subject: [PATCH 2/7] Add trimming test for Marshal.StructureToPtr with ByVal DateTime array (issue #127952) Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/d5cc9194-87ba-4a47-aab5-a1c8f5c11865 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com> --- .../MarshalStructureToPtrByValDateArray.cs | 43 +++++++++++++++++++ ...Runtime.InteropServices.TrimmingTests.proj | 5 +++ 2 files changed, 48 insertions(+) create mode 100644 src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs diff --git a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs new file mode 100644 index 00000000000000..f6133cfcd3209c --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Regression test for https://github.com/dotnet/runtime/issues/127952 +// Marshal.StructureToPtr / Marshal.DestroyStructure on a struct containing a +// ByValArray of DateTime values requires the DateMarshaler stub-helper to +// survive trimming. Without the fix this throws: +// System.Security.VerificationException: Method +// System.StubHelpers.StubHelpers.FreeArrayContents: type argument +// 'System.StubHelpers.DateMarshaler' violates the constraint of type +// parameter 'TMarshaler'. + +using System; +using System.Runtime.InteropServices; + +var structure = new StructWithDateArray() +{ + array = new DateTime[] + { + DateTime.Now, DateTime.Now + } +}; + +int size = Marshal.SizeOf(structure); +IntPtr memory = Marshal.AllocHGlobal(size); +try +{ + Marshal.StructureToPtr(structure, memory, false); + Marshal.StructureToPtr(structure, memory, true); +} +finally +{ + Marshal.DestroyStructure(memory, structure.GetType()); + Marshal.FreeHGlobal(memory); +} + +return 100; + +public struct StructWithDateArray +{ + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public DateTime[] array; +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj index 9aa8090bd00f56..7e4c1dba9cc74f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj +++ b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj @@ -26,6 +26,11 @@ IlcGenerateMstatFile;IlcGenerateDgmlFile + + + + + From 376b174a526a295dbc471eeb405da6ebf1f15153 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 May 2026 04:56:31 +0000 Subject: [PATCH 3/7] Preserve array marshaler metadata for trimming Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9c7a3bc4-8522-45c9-baab-648e64213b45 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com> --- .../src/ILLink/ILLink.Descriptors.Shared.xml | 5 +++++ 1 file changed, 5 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..d7869d604af9a9 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,11 @@ + + + + + From 15c4b5bfd7e318a6fb7fdc9055fa04ed665db396 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 May 2026 04:57:39 +0000 Subject: [PATCH 4/7] Clean up trimming test descriptor comments Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9c7a3bc4-8522-45c9-baab-648e64213b45 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com> --- .../src/ILLink/ILLink.Descriptors.Shared.xml | 2 +- .../System.Runtime.InteropServices.TrimmingTests.proj | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) 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 d7869d604af9a9..1e272bf0b36e08 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,7 +9,7 @@ - + diff --git a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj index 7e4c1dba9cc74f..a9cb239feae30e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj +++ b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj @@ -27,9 +27,8 @@ IlcGenerateMstatFile;IlcGenerateDgmlFile - - - + + From 4e7b47bc1538e02928b49f9fa79b16796531c00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 13 May 2026 14:50:48 +0900 Subject: [PATCH 5/7] Add marshaler types for various structures Added new marshaler types to address issue #128120. --- .../src/ILLink/ILLink.Descriptors.Shared.xml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 1e272bf0b36e08..5829024224e18f 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,10 +9,17 @@ - - - - + + + + + + + + + + + From 57e3fa4e394a6e0a901b140239374f59fbbcab69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 13 May 2026 03:37:53 -0700 Subject: [PATCH 6/7] Remove VariantBoolMarshaler from ILLink descriptors Removed VariantBoolMarshaler from the XML descriptors. --- .../src/ILLink/ILLink.Descriptors.Shared.xml | 1 - 1 file changed, 1 deletion(-) 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 5829024224e18f..4b7fef999247ca 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 @@ -15,7 +15,6 @@ - From 2a42b115ea24a21b869b84232276ec3c047df9b1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 21:06:10 +0000 Subject: [PATCH 7/7] Remove ByVal DateTime trimming test Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/6ef6819e-0aa3-4c84-af13-bc087b714afb Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com> --- .../MarshalStructureToPtrByValDateArray.cs | 43 ------------------- ...Runtime.InteropServices.TrimmingTests.proj | 4 -- 2 files changed, 47 deletions(-) delete mode 100644 src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs diff --git a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs deleted file mode 100644 index f6133cfcd3209c..00000000000000 --- a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/MarshalStructureToPtrByValDateArray.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Regression test for https://github.com/dotnet/runtime/issues/127952 -// Marshal.StructureToPtr / Marshal.DestroyStructure on a struct containing a -// ByValArray of DateTime values requires the DateMarshaler stub-helper to -// survive trimming. Without the fix this throws: -// System.Security.VerificationException: Method -// System.StubHelpers.StubHelpers.FreeArrayContents: type argument -// 'System.StubHelpers.DateMarshaler' violates the constraint of type -// parameter 'TMarshaler'. - -using System; -using System.Runtime.InteropServices; - -var structure = new StructWithDateArray() -{ - array = new DateTime[] - { - DateTime.Now, DateTime.Now - } -}; - -int size = Marshal.SizeOf(structure); -IntPtr memory = Marshal.AllocHGlobal(size); -try -{ - Marshal.StructureToPtr(structure, memory, false); - Marshal.StructureToPtr(structure, memory, true); -} -finally -{ - Marshal.DestroyStructure(memory, structure.GetType()); - Marshal.FreeHGlobal(memory); -} - -return 100; - -public struct StructWithDateArray -{ - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] - public DateTime[] array; -} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj index a9cb239feae30e..9aa8090bd00f56 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj +++ b/src/libraries/System.Runtime.InteropServices/tests/TrimmingTests/System.Runtime.InteropServices.TrimmingTests.proj @@ -26,10 +26,6 @@ IlcGenerateMstatFile;IlcGenerateDgmlFile - - - -