Skip to content

Non-blittable struct with explicit layout has wrong managed size  #100220

Closed
@jkotas

Description

@jkotas

Context #100206 (comment)

Repro

using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

Console.WriteLine(Unsafe.SizeOf<MyStruct>());

[StructLayout(LayoutKind.Explicit, Size = 9)]
struct MyStruct
{
    [FieldOffset(0)]
    public byte[] a;
    [FieldOffset(8)]
    public byte b;
}

Expected result (on x64)

16

Actual result

9

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