Skip to content

Commit 9d742b6

Browse files
Do not throw for Marshal.SizeOf(typeof(delegate*<void>)) (#113603)
1 parent 4f9ecbf commit 9d742b6

File tree

2 files changed

+7
-1
lines changed
  • src
    • coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices
    • libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal

2 files changed

+7
-1
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NativeAot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static int SizeOfHelper(RuntimeType t, bool throwIfNotMarshalable)
2020
{
2121
Debug.Assert(throwIfNotMarshalable);
2222

23-
if (t.IsPointer /* or IsFunctionPointer */)
23+
if (t.IsPointer || t.IsFunctionPointer)
2424
return IntPtr.Size;
2525

2626
if (t.IsByRef || t.IsArray || t.ContainsGenericParameters)

src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SizeOfTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public void SizeOf_Object_ReturnsExpected()
3131
Assert.NotEqual(0, Marshal.SizeOf(typeof(SomeTestStruct)));
3232
}
3333

34+
[Fact]
35+
public unsafe void SizeOf_FunctionPointer_ReturnsExpected()
36+
{
37+
Assert.Equal(IntPtr.Size, Marshal.SizeOf(typeof(delegate*<void>)));
38+
}
39+
3440
[Fact]
3541
public void SizeOf_Pointer_ReturnsExpected()
3642
{

0 commit comments

Comments
 (0)