TypeLoadException when a ref struct
using explicit layout has fields of type ref struct
#111260
Labels
ref struct
using explicit layout has fields of type ref struct
#111260
Description
Context: Found in .NET 9 when experimenting with
ref struct
in P/Invoke scenarios. I want to make it clear that I'm not using "ref fields" but rather only "ref structs"; the fields of the struct are notref
(pointer) but the type is ofref struct
(stack-only).Reproduction Steps
Expected behavior
A
ref struct
of explicit layout can have fields that are positioned usingFieldOffset
attribute where the type of the field is aref struct
without creating a runtime exception.Actual behavior
When a
ref struct
is using explicit struct layout, aSystem.TypeLoadException
can occur regarding the field offset of the struct's field which the type is anotherref struct
.Regression?
No response
Known Workarounds
ref
from the nested struct.Configuration
osx-arm64
)Other information
Hypothesis: The word
ref
in the context of a struct (stack-only) is confused to be in the context of a field (pointer); the field is mistaken for an object type with rules about field alignment when it's actually a struct.The text was updated successfully, but these errors were encountered: