Skip to content

Add support for the new System.Runtime.InteropServices.ExtendedLayoutAttribute #19190

Description

@jkoritzinsky

The interop team has decided to add a new mechanism to specify type layouts. In particular, the team has decided to use the last remaining value in the "Layout Kind" mask of a type def's attributes to represent "extended layout". When this value it set, the runtime will look for the System.Runtime.InteropServices.ExtendedLayoutAttribute to provide all layout information.

As part of the design process, we noticed that Roslyn blocks emitting a type with the last remaining value of the System.Runtime.InteropServices.LayoutKind enumeration in the StructLayout pseudo-attribute as the compiler can't map it to a valid TypeAttributes value. I do not know if F# does the same today.

The System.Runtime.InteropServices.ExtendedLayoutAttribute type was approved in dotnet/runtime#100896 and has the first part of runtime implementation (the TypeAttributes bit and the LayoutKind value) in dotnet/runtime#116082.

The support in F# should be either:

  • Allow the user to specify the ExtendedLayoutAttribute on a type. When they do so, the correct layout bit will be set. The user cannot manually specify the new "extended layout" value. The only way in F# to specify that value is to put this attribute on the type.
    • Disallow the FieldOffset attribute for extended layout types.
  • Block user usage of ExtendedLayoutAttribute.

There is a PR to add support to Roslyn for C# and VB.NET at dotnet/roslyn#78741

Activity

  1. added this to the Backlog milestone on Jan 5, 2026
  2. T-Gro commented on Jan 6, 2026

    @T-Gro
    Member

    @jkoritzinsky :

    Could you please help with crafting prompts for testing this properly?
    Also w.r.t to what it should be doing at runtime in an interop-relevant scenario.

  3. jkoritzinsky commented on Jan 6, 2026

    @jkoritzinsky
    MemberAuthor

    We've only implemented CStruct so far in .NET 11, which has identical behavior to LayoutKind.Sequential.

    It looks like you've got a good set of tests already in the PR. Left one comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-ImportAndInteropFeature Request

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions