diff --git a/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs b/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs index c7513ad80c1478..c1a0e142e8c8d0 100644 --- a/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs +++ b/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs @@ -405,7 +405,18 @@ public TypeDesc ResolveTypeHandle(long handle, ref bool dependsOnKnownNonLoadabl throw new Exception($"Invalid typedef {tinfo.TypeValue.TypeNameID:4x}"); } - TypeDefinitionHandle typedef = MetadataTokens.TypeDefinitionHandle(tinfo.TypeValue.TypeNameID & 0xFFFFFF); + int typedefRow = tinfo.TypeValue.TypeNameID & 0xFFFFFF; + // The runtime emits BulkType events for "minimal" MethodTables created by + // CreateMinimalMethodTable in coreclr (used for Reflection.Emit DynamicMethod + // hosts and the IL stub cache). These MTs have no typedef token and surface + // here as TypeNameID == 0x02000000 (rid 0). Treat them as unresolvable + // dynamic types so trace processing can continue. + if (typedefRow == 0) + { + dependsOnKnownNonLoadableType = true; + return null; + } + TypeDefinitionHandle typedef = MetadataTokens.TypeDefinitionHandle(typedefRow); MetadataType uninstantiatedType = (MetadataType)ecmaModule.GetType(typedef); // Instantiate the type if requested if ((tinfo.TypeValue.TypeParameters.Length != 0) && uninstantiatedType != null)