diff --git a/src/coreclr/md/compiler/importhelper.cpp b/src/coreclr/md/compiler/importhelper.cpp index fa95a6b7efd4a6..062011b6938643 100644 --- a/src/coreclr/md/compiler/importhelper.cpp +++ b/src/coreclr/md/compiler/importhelper.cpp @@ -2681,64 +2681,70 @@ HRESULT ImportHelper::ImportTypeRef( mdToken tkImplementation; // Implementation token for ExportedType. if (IsNilToken(tkOuterImportRes)) { - // BUG FIX:: URT 13626 - // Well, before all of the clients generate AR for SPCL reference, it is not true - // that tkOuterImportRes == nil will imply that we have to find such an entry in the import manifest!! - - // Look for a ExportedType entry in the import Assembly. Its an error - // if we don't find a ExportedType entry. - mdExportedType tkExportedType; - hr = pCommonAssemImport->CommonFindExportedType( - cqaNesterNamespaces[cqaNesters.Size() - 1], - cqaNesterNames[cqaNesters.Size() - 1], - mdTokenNil, - &tkExportedType); - if (SUCCEEDED(hr)) - { - IfFailGo(pCommonAssemImport->CommonGetExportedTypeProps( - tkExportedType, - NULL, - NULL, - &tkImplementation)); - if (TypeFromToken(tkImplementation) == mdtFile) - { - // Type is from a different Assembly. - IfFailGo(CreateAssemblyRefFromAssembly(pMiniMdAssemEmit, - pMiniMdEmit, - pCommonAssemImport, - pbHashValue, - cbHashValue, - &tkOuterEmitRes)); - } - else if (TypeFromToken(tkImplementation) == mdtAssemblyRef) + if (pCommonAssemImport != NULL) + { + // BUG FIX:: URT 13626 + // Well, before all of the clients generate AR for SPCL reference, it is not true + // that tkOuterImportRes == nil will imply that we have to find such an entry in the import manifest!! + + // Look for a ExportedType entry in the import Assembly. Its an error + // if we don't find a ExportedType entry. + mdExportedType tkExportedType; + hr = pCommonAssemImport->CommonFindExportedType( + cqaNesterNamespaces[cqaNesters.Size() - 1], + cqaNesterNames[cqaNesters.Size() - 1], + mdTokenNil, + &tkExportedType); + if (SUCCEEDED(hr)) { - // This folds into the case where the Type is AssemblyRef. So - // let it fall through to that case. + IfFailGo(pCommonAssemImport->CommonGetExportedTypeProps( + tkExportedType, + NULL, + NULL, + &tkImplementation)); + if (TypeFromToken(tkImplementation) == mdtFile) + { + // Type is from a different Assembly. + IfFailGo(CreateAssemblyRefFromAssembly(pMiniMdAssemEmit, + pMiniMdEmit, + pCommonAssemImport, + pbHashValue, + cbHashValue, + &tkOuterEmitRes)); + } + else if (TypeFromToken(tkImplementation) == mdtAssemblyRef) + { + // This folds into the case where the Type is AssemblyRef. So + // let it fall through to that case. - // Remember that this AssemblyRef token is actually from the Manifest scope not - // the module scope!!! - bAssemblyRefFromAssemScope = true; - tkOuterImportRes = tkImplementation; + // Remember that this AssemblyRef token is actually from the Manifest scope not + // the module scope!!! + bAssemblyRefFromAssemScope = true; + tkOuterImportRes = tkImplementation; + } + else + _ASSERTE(!"Unexpected ExportedType implementation token."); } else - _ASSERTE(!"Unexpected ExportedType implementation token."); - } - else - { - // In this case, we will just move over the TypeRef with Nil ResolutionScope. - hr = NOERROR; - tkOuterEmitRes = mdTokenNil; + { + // In this case, we will just move over the TypeRef with Nil ResolutionScope. + hr = NOERROR; + tkOuterEmitRes = mdTokenNil; + } } } else if (TypeFromToken(tkOuterImportRes) == mdtModule) { - // Type is from a different Assembly. - IfFailGo(CreateAssemblyRefFromAssembly(pMiniMdAssemEmit, - pMiniMdEmit, - pCommonAssemImport, - pbHashValue, - cbHashValue, - &tkOuterEmitRes)); + if (pCommonAssemImport != NULL) + { + // Type is from a different Assembly. + IfFailGo(CreateAssemblyRefFromAssembly(pMiniMdAssemEmit, + pMiniMdEmit, + pCommonAssemImport, + pbHashValue, + cbHashValue, + &tkOuterEmitRes)); + } } // Not else if, because mdtModule case above could change // tkOuterImportRes to an AssemblyRef. @@ -2843,13 +2849,16 @@ HRESULT ImportHelper::ImportTypeRef( } else if (TypeFromToken(tkOuterImportRes) == mdtModuleRef) { - // Type is from a different Assembly. - IfFailGo(CreateAssemblyRefFromAssembly(pMiniMdAssemEmit, - pMiniMdEmit, - pCommonAssemImport, - pbHashValue, - cbHashValue, - &tkOuterEmitRes)); + if (pCommonAssemImport != NULL) + { + // Type is from a different Assembly. + IfFailGo(CreateAssemblyRefFromAssembly(pMiniMdAssemEmit, + pMiniMdEmit, + pCommonAssemImport, + pbHashValue, + cbHashValue, + &tkOuterEmitRes)); + } } }