Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
Comment on lines +24 to +35

return 100;

public struct StructWithDateArray
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public DateTime[] array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<TestConsoleAppSourceFiles Include="TypeMap.cs" NativeAotOnly="true">
<EnabledProperties>IlcGenerateMstatFile;IlcGenerateDgmlFile</EnabledProperties>
</TestConsoleAppSourceFiles>

<!-- Regression test for https://github.com/dotnet/runtime/issues/127952 -->
<!-- Marshal.StructureToPtr on a struct containing a ByValArray of DateTime values -->
<!-- is expected to fail on tvos-arm64 until the underlying issue is fixed. -->
<TestConsoleAppSourceFiles Include="MarshalStructureToPtrByValDateArray.cs" />
Comment on lines +30 to +33
</ItemGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
Expand Down
Loading