Skip to content

Commit 3b56e41

Browse files
committed
Add library path to DLL search path to handle bundle dependencies on .net framework
1 parent 2d1474b commit 3b56e41

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,24 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
132132
[DllImport("libdl", EntryPoint = "dlopen")]
133133
private static extern IntPtr LoadUnixLibrary(string path, int flags);
134134

135-
[DllImport("kernel32", EntryPoint = "LoadLibrary")]
136-
private static extern IntPtr LoadWindowsLibrary(string path);
135+
[DllImport("kernel32", EntryPoint = "AddDllDirectory", CharSet = CharSet.Unicode)]
136+
private static extern IntPtr AddDllDirectory(string path);
137+
138+
[DllImport("kernel32", EntryPoint = "LoadLibraryExW", CharSet = CharSet.Unicode)]
139+
private static extern IntPtr LoadWindowsLibraryEx(string path, IntPtr hFile, uint flags);
140+
141+
private const uint LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000;
142+
143+
private static IntPtr LoadWindowsLibrary(string path)
144+
{
145+
var directory = Path.GetDirectoryName(path);
146+
if (directory != null)
147+
{
148+
AddDllDirectory(directory);
149+
}
150+
151+
return LoadWindowsLibraryEx(path, IntPtr.Zero, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
152+
}
137153

138154
// Avoid inlining this method because otherwise mono's JITter may try
139155
// to load the library _before_ we've configured the path.

0 commit comments

Comments
 (0)