Skip to content

[mono] Mono doesn't respect explicit size for structures when marked with LayoutKind.Sequential #101432

@matouskozak

Description

@matouskozak

Mono doesn't respect explicit struct size when combined with sequential layout, i.e., when using [StructLayout(LayoutKind.Sequential, Size = X)], the structure doesn't have the desired size X.

Repro code:

using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Size = 12)]
struct F3_S0_S0
{
    public nint F0;
    public uint F1;

    public F3_S0_S0(nint f0, uint f1)
    {
        F0 = f0;
        F1 = f1;
    }
}

private static void Main(string[] args)
{
    Console.WriteLine(Marshal.SizeOf(typeof(F3_S0_S0)));
}

Mono output:

16

CoreCLR output:

12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions