Fix trimming for Marshal.StructureToPtr with ByVal DateTime arrays#128020
Fix trimming for Marshal.StructureToPtr with ByVal DateTime arrays#128020
Conversation
…y (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>
|
Confirmed this test reproduces the issue: Now to the fix. @copilot the theory is that the issue is that trimming is removing the interface that TMarshaler is constrained with ( Add the interface to src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.Shared.xml and ensure all members on it are kept. The docs on the XML file format are at docs/tools/illink/data-formats.md (it's the "Descriptor Format"). |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9c7a3bc4-8522-45c9-baab-648e64213b45 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9c7a3bc4-8522-45c9-baab-648e64213b45 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
... Implemented in 376b174, with comment cleanup in 15c4b5b. I preserved |
|
The test now passes (it doesn't with Mono, but that's a Mono problem with marshalling DateTime in general). However, I'm not convinced this is the right fix, I'll need to study what exactly is the reflection-like mechanism that #126911 introduced here. |
Description
Fixes a trimming issue from #127952 where
Marshal.StructureToPtr/Marshal.DestroyStructureon a struct containing a[MarshalAs(UnmanagedType.ByValArray)] DateTime[]field could throwSystem.Security.VerificationExceptionafter trimming because required array marshaler metadata was removed.The fix preserves the array marshaler interfaces and
DateMarshalermembers inSystem.Private.CoreLib's shared ILLink descriptor soStubHelpers.FreeArrayContents<T, TMarshaler>generic constraints and concrete interface implementations remain valid after trimming.Changes
ILLink.Descriptors.Shared.xml— preservesSystem.StubHelpers.IArrayMarshaler\2,System.StubHelpers.IArrayElementMarshaler`2, andSystem.StubHelpers.DateMarshaler` members.TrimmingTests/MarshalStructureToPtrByValDateArray.cs— adds a standalone trimming regression test mirroringStructureToPtrTests.StructureToPtr_ByValDateArray_Success.System.Runtime.InteropServices.TrimmingTests.proj— registers the new trimming test file.Changes to the tests
MarshalStructureToPtrByValDateArray.csundersrc/libraries/System.Runtime.InteropServices/tests/TrimmingTests/.dotnet build System.Runtime.InteropServices.TrimmingTests.proj /p:TestTrimming=true.Microsoft Reviewers: Open in VS Code
Original prompt
This pull request was created from Copilot chat.