diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/LibraryRootProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/LibraryRootProvider.cs index 00fb2285f85d5a..c47d26869319f9 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/LibraryRootProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/LibraryRootProvider.cs @@ -99,9 +99,7 @@ public static void CheckCanGenerateMethod(MethodDesc method) private static void CheckTypeCanBeUsedInSignature(TypeDesc type) { - MetadataType defType = type as MetadataType; - - defType?.ComputeTypeContainsGCPointers(); + ((CompilerTypeSystemContext)type.Context).EnsureLoadableType(type); } } } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RootingServiceProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RootingServiceProvider.cs index fc13ed9a298ee4..0f0b4d2a9c3333 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RootingServiceProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RootingServiceProvider.cs @@ -46,7 +46,14 @@ public void AddCompilationRoot(TypeDesc type, string reason) public void AddReflectionRoot(TypeDesc type, string reason) { - _factory.TypeSystemContext.EnsureLoadableType(type); + TypeDesc lookedAtType = type; + do + { + _factory.TypeSystemContext.EnsureLoadableType(lookedAtType); + lookedAtType = (lookedAtType as MetadataType)?.ContainingType; + } + while (lookedAtType != null); + _rootAdder(_factory.ReflectedType(type), reason); } @@ -64,6 +71,7 @@ public void AddReflectionRoot(FieldDesc field, string reason) if (!_factory.MetadataManager.IsReflectionBlocked(field)) { _factory.TypeSystemContext.EnsureLoadableType(field.OwningType); + _factory.TypeSystemContext.EnsureLoadableType(field.FieldType); _rootAdder(_factory.ReflectedField(field), reason); } }