diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunMetadataFieldLayoutAlgorithm.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunMetadataFieldLayoutAlgorithm.cs index 4cf6d65ea43904..b1bd46ae269c97 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunMetadataFieldLayoutAlgorithm.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunMetadataFieldLayoutAlgorithm.cs @@ -818,10 +818,24 @@ protected override ComputedInstanceFieldLayout ComputeInstanceFieldLayout(Metada { if (type.IsExplicitLayout) { + // Works around https://github.com/dotnet/runtime/issues/102868 + if (!type.IsValueType && + (type.MetadataBaseType is MetadataType baseType && baseType.IsSequentialLayout)) + { + ThrowHelper.ThrowTypeLoadException(type); + } + return ComputeExplicitFieldLayout(type, numInstanceFields); } else if (type.IsSequentialLayout && !type.ContainsGCPointers) { + // Works around https://github.com/dotnet/runtime/issues/102868 + if (!type.IsValueType && + (type.MetadataBaseType is MetadataType baseType && baseType.IsExplicitLayout)) + { + ThrowHelper.ThrowTypeLoadException(type); + } + return ComputeSequentialFieldLayout(type, numInstanceFields); } else