@@ -6879,13 +6879,12 @@ HMODULE NDirect::LoadLibraryModuleViaHost(NDirectMethodDesc * pMD, AppDomain* pD
6879
6879
#endif // defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
6880
6880
6881
6881
// Try to load the module alongside the assembly where the PInvoke was declared.
6882
- HMODULE NDirect::LoadFromPInvokeAssemblyDirectory (NDirectMethodDesc *pMD , LPCWSTR libName, DWORD flags, LoadLibErrorTracker *pErrorTracker)
6882
+ HMODULE NDirect::LoadFromPInvokeAssemblyDirectory (Assembly *pAssembly , LPCWSTR libName, DWORD flags, LoadLibErrorTracker *pErrorTracker)
6883
6883
{
6884
6884
STANDARD_VM_CONTRACT;
6885
6885
6886
6886
HMODULE hmod = NULL ;
6887
6887
6888
- Assembly* pAssembly = pMD->GetMethodTable ()->GetAssembly ();
6889
6888
SString path = pAssembly->GetManifestFile ()->GetPath ();
6890
6889
6891
6890
SString::Iterator lastPathSeparatorIter = path.End ();
@@ -6901,6 +6900,7 @@ HMODULE NDirect::LoadFromPInvokeAssemblyDirectory(NDirectMethodDesc *pMD, LPCWST
6901
6900
return hmod;
6902
6901
}
6903
6902
6903
+ #ifdef FEATURE_CORECLR
6904
6904
// Try to load the module from the native DLL search directories
6905
6905
HMODULE NDirect::LoadFromNativeDllSearchDirectories (AppDomain* pDomain, LPCWSTR libName, DWORD flags, LoadLibErrorTracker *pErrorTracker)
6906
6906
{
@@ -6924,6 +6924,7 @@ HMODULE NDirect::LoadFromNativeDllSearchDirectories(AppDomain* pDomain, LPCWSTR
6924
6924
6925
6925
return hmod;
6926
6926
}
6927
+ #endif // FEATURE_CORECLR
6927
6928
6928
6929
HINSTANCE NDirect::LoadLibraryModule (NDirectMethodDesc * pMD, LoadLibErrorTracker * pErrorTracker)
6929
6930
{
@@ -7100,7 +7101,8 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke
7100
7101
}
7101
7102
else if (searchAssemblyDirectory)
7102
7103
{
7103
- hmod = LoadFromPInvokeAssemblyDirectory (pMD, wszLibName, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
7104
+ Assembly* pAssembly = pMD->GetMethodTable ()->GetAssembly ();
7105
+ hmod = LoadFromPInvokeAssemblyDirectory (pAssembly, wszLibName, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
7104
7106
7105
7107
#ifndef FEATURE_CORECLR
7106
7108
if (hmod == NULL )
@@ -7148,6 +7150,15 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke
7148
7150
7149
7151
pathFromCodebase.Append (wszLibName);
7150
7152
7153
+ SString path = pAssembly->GetManifestFile ()->GetPath ();
7154
+ SString::Iterator i = path.End ();
7155
+ if (PEAssembly::FindLastPathSeparator (path, i))
7156
+ {
7157
+ i++;
7158
+ path.Truncate (i);
7159
+ path.Append (wszLibName);
7160
+ }
7161
+
7151
7162
if (!pathFromCodebase.EqualsCaseInsensitive (path, PEImage::GetFileSystemLocale ()))
7152
7163
{
7153
7164
hmod = LocalLoadLibraryHelper (pathFromCodebase, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
@@ -7227,7 +7238,8 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke
7227
7238
7228
7239
if (libNameIsRelativePath && searchAssemblyDirectory)
7229
7240
{
7230
- hmod = LoadFromPInvokeAssemblyDirectory (pMD, currLibNameVariation, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
7241
+ Assembly *pAssembly = pMD->GetMethodTable ()->GetAssembly ();
7242
+ hmod = LoadFromPInvokeAssemblyDirectory (pAssembly, currLibNameVariation, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
7231
7243
if (hmod != NULL )
7232
7244
break ;
7233
7245
}
0 commit comments