From: Gaurav Khanna Date: Sat, 22 Oct 2016 16:18:26 +0000 (-0700) Subject: Fix Binder based PInvoke resolution for dynamic assembly (dotnet/coreclr#7770) X-Git-Tag: submit/tizen/20210909.063632~11030^2~9103 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=87f3c5d98e7e26293466588cfe87706725289949;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix Binder based PInvoke resolution for dynamic assembly (dotnet/coreclr#7770) Commit migrated from https://github.com/dotnet/coreclr/commit/5ff10a5b41d5481e21df9bbf5a4e8b419895530d --- diff --git a/src/coreclr/src/vm/assembly.cpp b/src/coreclr/src/vm/assembly.cpp index 481bcea..b3e7611 100644 --- a/src/coreclr/src/vm/assembly.cpp +++ b/src/coreclr/src/vm/assembly.cpp @@ -762,7 +762,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, CreateDynamicAssemblyArgs // using an actual binder. As a result, we will assume the same binding/loadcontext information for the dynamic assembly as its // caller/creator to ensure that any assembly loads triggered by the dynamic assembly are resolved using the intended load context. // - // If the creator assembly has a HostAssembly associated with it, then use it for binding. Otherwise, ithe creator is dynamic + // If the creator assembly has a HostAssembly associated with it, then use it for binding. Otherwise, the creator is dynamic // and will have a fallback load context binder associated with it. ICLRPrivBinder *pFallbackLoadContextBinder = nullptr; diff --git a/src/coreclr/src/vm/dllimport.cpp b/src/coreclr/src/vm/dllimport.cpp index 551e9b2..f724169 100644 --- a/src/coreclr/src/vm/dllimport.cpp +++ b/src/coreclr/src/vm/dllimport.cpp @@ -6832,15 +6832,29 @@ HMODULE NDirect::LoadLibraryModuleViaHost(NDirectMethodDesc * pMD, AppDomain* pD CLRPrivBinderCoreCLR *pTPABinder = pDomain->GetTPABinderContext(); Assembly* pAssembly = pMD->GetMethodTable()->GetAssembly(); - PTR_ICLRPrivBinder pBindingContext = pAssembly->GetManifestFile()->GetBindingContext(); + PEFile *pManifestFile = pAssembly->GetManifestFile(); + PTR_ICLRPrivBinder pBindingContext = pManifestFile->GetBindingContext(); //Step 0: Check if the assembly was bound using TPA. // The Binding Context can be null or an overridden TPA context if (pBindingContext == NULL) { - return NULL; + pBindingContext = nullptr; + + // If the assembly does not have a binder associated with it explicitly, then check if it is + // a dynamic assembly, or not, since they can have a fallback load context associated with them. + if (pManifestFile->IsDynamic()) + { + pBindingContext = pManifestFile->GetFallbackLoadContextBinder(); + } } - + + // If we do not have any binder associated, then return to the default resolution mechanism. + if (pBindingContext == nullptr) + { + return NULL; + } + UINT_PTR assemblyBinderID = 0; IfFailThrow(pBindingContext->GetBinderID(&assemblyBinderID));