Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a4757bc

Browse files
authored
Merge pull request #7796 from gkhanna79/PortDAPinvoke
Port: Invoke correct pinvoke resolution override for dynamically generated assembly.
2 parents c00e407 + c3c71f9 commit a4757bc

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/vm/assembly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, CreateDynamicAssemblyArgs
762762
// using an actual binder. As a result, we will assume the same binding/loadcontext information for the dynamic assembly as its
763763
// caller/creator to ensure that any assembly loads triggered by the dynamic assembly are resolved using the intended load context.
764764
//
765-
// If the creator assembly has a HostAssembly associated with it, then use it for binding. Otherwise, ithe creator is dynamic
765+
// If the creator assembly has a HostAssembly associated with it, then use it for binding. Otherwise, the creator is dynamic
766766
// and will have a fallback load context binder associated with it.
767767
ICLRPrivBinder *pFallbackLoadContextBinder = nullptr;
768768

src/vm/dllimport.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6832,15 +6832,29 @@ HMODULE NDirect::LoadLibraryModuleViaHost(NDirectMethodDesc * pMD, AppDomain* pD
68326832
CLRPrivBinderCoreCLR *pTPABinder = pDomain->GetTPABinderContext();
68336833
Assembly* pAssembly = pMD->GetMethodTable()->GetAssembly();
68346834

6835-
PTR_ICLRPrivBinder pBindingContext = pAssembly->GetManifestFile()->GetBindingContext();
6835+
PEFile *pManifestFile = pAssembly->GetManifestFile();
6836+
PTR_ICLRPrivBinder pBindingContext = pManifestFile->GetBindingContext();
68366837

68376838
//Step 0: Check if the assembly was bound using TPA.
68386839
// The Binding Context can be null or an overridden TPA context
68396840
if (pBindingContext == NULL)
68406841
{
6841-
return NULL;
6842+
pBindingContext = nullptr;
6843+
6844+
// If the assembly does not have a binder associated with it explicitly, then check if it is
6845+
// a dynamic assembly, or not, since they can have a fallback load context associated with them.
6846+
if (pManifestFile->IsDynamic())
6847+
{
6848+
pBindingContext = pManifestFile->GetFallbackLoadContextBinder();
6849+
}
68426850
}
6843-
6851+
6852+
// If we do not have any binder associated, then return to the default resolution mechanism.
6853+
if (pBindingContext == nullptr)
6854+
{
6855+
return NULL;
6856+
}
6857+
68446858
UINT_PTR assemblyBinderID = 0;
68456859
IfFailThrow(pBindingContext->GetBinderID(&assemblyBinderID));
68466860

0 commit comments

Comments
 (0)