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

Commit efde18c

Browse files
committed
[adityam] Fix break in DllImport code for Desktop CLR.
[tfs-changeset: 1540922]
1 parent d12f402 commit efde18c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/vm/dllimport.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6879,13 +6879,12 @@ HMODULE NDirect::LoadLibraryModuleViaHost(NDirectMethodDesc * pMD, AppDomain* pD
68796879
#endif //defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
68806880

68816881
// 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)
68836883
{
68846884
STANDARD_VM_CONTRACT;
68856885

68866886
HMODULE hmod = NULL;
68876887

6888-
Assembly* pAssembly = pMD->GetMethodTable()->GetAssembly();
68896888
SString path = pAssembly->GetManifestFile()->GetPath();
68906889

68916890
SString::Iterator lastPathSeparatorIter = path.End();
@@ -6901,6 +6900,7 @@ HMODULE NDirect::LoadFromPInvokeAssemblyDirectory(NDirectMethodDesc *pMD, LPCWST
69016900
return hmod;
69026901
}
69036902

6903+
#ifdef FEATURE_CORECLR
69046904
// Try to load the module from the native DLL search directories
69056905
HMODULE NDirect::LoadFromNativeDllSearchDirectories(AppDomain* pDomain, LPCWSTR libName, DWORD flags, LoadLibErrorTracker *pErrorTracker)
69066906
{
@@ -6924,6 +6924,7 @@ HMODULE NDirect::LoadFromNativeDllSearchDirectories(AppDomain* pDomain, LPCWSTR
69246924

69256925
return hmod;
69266926
}
6927+
#endif // FEATURE_CORECLR
69276928

69286929
HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracker * pErrorTracker)
69296930
{
@@ -7100,7 +7101,8 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke
71007101
}
71017102
else if (searchAssemblyDirectory)
71027103
{
7103-
hmod = LoadFromPInvokeAssemblyDirectory(pMD, wszLibName, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
7104+
Assembly* pAssembly = pMD->GetMethodTable()->GetAssembly();
7105+
hmod = LoadFromPInvokeAssemblyDirectory(pAssembly, wszLibName, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
71047106

71057107
#ifndef FEATURE_CORECLR
71067108
if (hmod == NULL)
@@ -7148,6 +7150,15 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke
71487150

71497151
pathFromCodebase.Append(wszLibName);
71507152

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+
71517162
if (!pathFromCodebase.EqualsCaseInsensitive(path, PEImage::GetFileSystemLocale()))
71527163
{
71537164
hmod = LocalLoadLibraryHelper(pathFromCodebase, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
@@ -7227,7 +7238,8 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke
72277238

72287239
if (libNameIsRelativePath && searchAssemblyDirectory)
72297240
{
7230-
hmod = LoadFromPInvokeAssemblyDirectory(pMD, currLibNameVariation, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
7241+
Assembly *pAssembly = pMD->GetMethodTable()->GetAssembly();
7242+
hmod = LoadFromPInvokeAssemblyDirectory(pAssembly, currLibNameVariation, loadWithAlteredPathFlags | dllImportSearchPathFlag, pErrorTracker);
72317243
if (hmod != NULL)
72327244
break;
72337245
}

src/vm/dllimport.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ class NDirect
133133
private:
134134
NDirect() {LIMITED_METHOD_CONTRACT;}; // prevent "new"'s on this class
135135

136+
#ifdef FEATURE_CORECLR
136137
static HMODULE LoadFromNativeDllSearchDirectories(AppDomain* pDomain, LPCWSTR libName, DWORD flags, LoadLibErrorTracker *pErrorTracker);
137-
static HMODULE LoadFromPInvokeAssemblyDirectory(NDirectMethodDesc *pMD, LPCWSTR libName, DWORD flags, LoadLibErrorTracker *pErrorTracker);
138+
#endif
139+
static HMODULE LoadFromPInvokeAssemblyDirectory(Assembly *pAssembly, LPCWSTR libName, DWORD flags, LoadLibErrorTracker *pErrorTracker);
138140

139141
#if defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
140142
static HMODULE LoadLibraryModuleViaHost(NDirectMethodDesc * pMD, AppDomain* pDomain, const wchar_t* wszLibName);

0 commit comments

Comments
 (0)