Skip to content

Struct with self-referencing ImmutableArray static field causes TypeLoadException #104519

Closed as not planned
@JakeYallop

Description

@JakeYallop

Description

A struct with a static ImmuatableArray field that references the enclosing struct causes a TypeLoadException on start.

Reproduction Steps

sharplab

dotnet new console
Console.WriteLine(new MyStruct());

public struct MyStruct
{
    static ImmutableArray<MyStruct> One;
}

Expected behavior

No error

Actual behavior

Unhandled exception. System.TypeLoadException: Could not load type 'MyStruct' from assembly 'StructRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at Program.<Main>$(String[] args)

Regression?

No - reproducible on .NET 8/7/6 as well.

Known Workarounds

No response

Configuration

.NET SDK:
 Version:           9.0.100-preview.5.24307.3
 Commit:            35b2c21ea6
 Workload version:  9.0.100-manifests.6407b7e4
 MSBuild version:   17.11.0-preview-24279-02+b963c24ef

Other information

No response

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