Skip to content

Commit a6e374d

Browse files
committed
Always try to use native library path from GlobalSettings
1 parent 0659bf5 commit a6e374d

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@ internal static class NativeMethods
2727

2828
static NativeMethods()
2929
{
30-
if (Platform.IsRunningOnNetFramework() || Platform.IsRunningOnNetCore())
30+
var nativeLibraryDir = GlobalSettings.GetAndLockNativeLibraryPath();
31+
32+
if (nativeLibraryDir != null)
3133
{
32-
string nativeLibraryDir = GlobalSettings.GetAndLockNativeLibraryPath();
33-
if (nativeLibraryDir != null)
34+
var nativeLibraryPath = Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension());
35+
36+
// Try to load the library from the path explicitly.
37+
// If this call succeeds, further DllImports will find the library loaded and not attempt to load it again.
38+
// If it fails, the next DllImport will load the library from safe directories.
39+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
40+
{
41+
LoadWindowsLibrary(nativeLibraryPath);
42+
}
43+
else
3444
{
35-
string nativeLibraryPath = Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension());
36-
37-
// Try to load the .dll from the path explicitly.
38-
// If this call succeeds further DllImports will find the library loaded and not attempt to load it again.
39-
// If it fails the next DllImport will load the library from safe directories.
40-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
41-
{
42-
LoadWindowsLibrary(nativeLibraryPath);
43-
}
44-
else
45-
{
46-
LoadUnixLibrary(nativeLibraryPath, RTLD_NOW);
47-
}
45+
LoadUnixLibrary(nativeLibraryPath, RTLD_NOW);
4846
}
4947
}
5048

0 commit comments

Comments
 (0)