From 9d86bc689856df25d1826b8418d7b251dd88f19e Mon Sep 17 00:00:00 2001 From: Gaurav Khanna Date: Tue, 19 Jul 2016 23:49:45 -0700 Subject: [PATCH] Fix for CoreCLR 6269 - Trigger formal binding if domain-wide cache does not have entry for an assembly in custom load context. (#6335) --- src/vm/assemblyspec.cpp | 23 ----------------------- src/vm/coreassemblyspec.cpp | 22 ++++++++++++++++++---- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/vm/assemblyspec.cpp b/src/vm/assemblyspec.cpp index b3707d7..5baf588 100644 --- a/src/vm/assemblyspec.cpp +++ b/src/vm/assemblyspec.cpp @@ -1850,29 +1850,6 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::GetAssembly } pEntry = (AssemblyBinding *) m_map.LookupValue(lookupKey, pSpec); - if (pEntry == (AssemblyBinding *) INVALIDENTRY) - { - // We didnt find the AssemblyBinding entry against the binder of the parent assembly. - // It is possible that the AssemblySpec corresponds to a TPA assembly, so try the lookup - // against the TPABinder context. - ICLRPrivBinder* pTPABinderContext = pSpecDomain->GetTPABinderContext(); - if ((pTPABinderContext != NULL) && !AreSameBinderInstance(pTPABinderContext, pBinderContextForLookup)) - { - UINT_PTR tpaBinderID = 0; - HRESULT hr = pTPABinderContext->GetBinderID(&tpaBinderID); - _ASSERTE(SUCCEEDED(hr)); - lookupKey = key^tpaBinderID; - - // Set the binding context in AssemblySpec to be TPABinder - // as that will be used in the Lookup operation below. - if (fGetBindingContextFromParent) - { - pSpec->SetBindingContext(pTPABinderContext); - } - - pEntry = (AssemblyBinding *) m_map.LookupValue(lookupKey, pSpec); - } - } // Reset the binding context if one was originally never present in the AssemblySpec and we didnt find any entry // in the cache. diff --git a/src/vm/coreassemblyspec.cpp b/src/vm/coreassemblyspec.cpp index caa9f17..310c663 100644 --- a/src/vm/coreassemblyspec.cpp +++ b/src/vm/coreassemblyspec.cpp @@ -183,9 +183,16 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, &pPrivAsm); } + bool fBoundUsingTPABinder = false; if(SUCCEEDED(hr)) { _ASSERTE(pPrivAsm != nullptr); + + if (AreSameBinderInstance(pTPABinder, reinterpret_cast(pPrivAsm.Extract()))) + { + fBoundUsingTPABinder = true; + } + result = BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(pPrivAsm.Extract()); _ASSERTE(result != nullptr); } @@ -193,13 +200,20 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, pResult->SetHRBindResult(hr); if (SUCCEEDED(hr)) { - BOOL fIsInGAC = pAppDomain->IsImageFromTrustedPath(result->GetNativeOrILPEImage()); + BOOL fIsInGAC = FALSE; BOOL fIsOnTpaList = FALSE; - const SString &sImagePath = result->GetNativeOrILPEImage()->GetPath(); - if (pTPABinder->IsInTpaList(sImagePath)) + + // Only initialize TPA/GAC status if we bound using DefaultContext + if (fBoundUsingTPABinder == true) { - fIsOnTpaList = TRUE; + fIsInGAC = pAppDomain->IsImageFromTrustedPath(result->GetNativeOrILPEImage()); + const SString &sImagePath = result->GetNativeOrILPEImage()->GetPath(); + if (pTPABinder->IsInTpaList(sImagePath)) + { + fIsOnTpaList = TRUE; + } } + pResult->Init(result,fIsInGAC, fIsOnTpaList); } else if (FAILED(hr) && (fThrowOnFileNotFound || (!Assembly::FileNotFound(hr)))) -- 2.7.4