diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/AnalysisBasedMetadataManager.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/AnalysisBasedMetadataManager.cs index 8ad71eb3db5b5..8bda4a18f3b5a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/AnalysisBasedMetadataManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/AnalysisBasedMetadataManager.cs @@ -254,21 +254,19 @@ public bool GeneratesMetadata(EcmaModule module, CustomAttributeHandle caHandle) public bool GeneratesMetadata(EcmaModule module, ExportedTypeHandle exportedTypeHandle) { - try - { - // We'll possibly need to do something else here if we ever use this MetadataManager - // with compilation modes that generate multiple metadata blobs. - // (Multi-module or .NET Native style shared library.) - // We are currently missing type forwarders pointing to the other blobs. - var targetType = (MetadataType)module.GetObject(exportedTypeHandle); - return GeneratesMetadata(targetType); - } - catch (TypeSystemException) + // We'll possibly need to do something else here if we ever use this MetadataManager + // with compilation modes that generate multiple metadata blobs. + // (Multi-module or .NET Native style shared library.) + // We are currently missing type forwarders pointing to the other blobs. + var targetType = (MetadataType)module.GetObject(exportedTypeHandle, NotFoundBehavior.ReturnNull); + if (targetType == null) { // No harm in generating a forwarder that didn't resolve. // We'll get matching behavior at runtime. return true; } + + return GeneratesMetadata(targetType); } public bool IsBlocked(MetadataType typeDef) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs index a55507fc53089..ef615ac558bd1 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs @@ -885,19 +885,16 @@ public bool GeneratesMetadata(EcmaModule module, CustomAttributeHandle caHandle) public bool GeneratesMetadata(EcmaModule module, ExportedTypeHandle exportedTypeHandle) { - try - { - // Generate the forwarder only if we generated the target type. - // If the target type is in a different compilation group, assume we generated it there. - var targetType = (MetadataType)module.GetObject(exportedTypeHandle); - return GeneratesMetadata(targetType) || !_factory.CompilationModuleGroup.ContainsType(targetType); - } - catch (TypeSystemException) + // Generate the forwarder only if we generated the target type. + // If the target type is in a different compilation group, assume we generated it there. + var targetType = (MetadataType)module.GetObject(exportedTypeHandle, NotFoundBehavior.ReturnNull); + if (targetType == null) { // No harm in generating a forwarder that didn't resolve. // We'll get matching behavior at runtime. return true; } + return GeneratesMetadata(targetType) || !_factory.CompilationModuleGroup.ContainsType(targetType); } public bool IsBlocked(MetadataType typeDef)