8000 Merge pull request #1741 from qmfrederik/fixes/resolve-dll-no-throw · crazygoodcode/libgit2sharp@58410d5 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 58410d5

Browse files
authored
Merge pull request libgit2#1741 from qmfrederik/fixes/resolve-dll-no-throw
NativeMethods.ResolveDll: Avoid exceptions
2 parents 09e8977 + 79870b0 commit 58410d5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,17 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
156156
// The <rid> ends with the processor architecture. e.g. fedora-x64.
157157
string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location);
158158
string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
159-
foreach (var runtimeFolder in Directory.GetDirectories(Path.Combine(assemblyDirectory, "runtimes"), $"*-{processorArchitecture}"))
159+
string runtimesDirectory = Path.Combine(assemblyDirectory, "runtimes");
160+
161+
if (Directory.Exists(runtimesDirectory))
160162
{
161-
string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so");
162-
if (TryLoadLibrary(libPath, out handle))
163+
foreach (var runtimeFolder in Directory.GetDirectories(runtimesDirectory, $"*-{processorArchitecture}"))
163164
{
164-
return handle;
165+
string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so");
166+
if (TryLoadLibrary(libPath, out handle))
167+
{
168+
return handle;
169+
}
165170
}
166171
}
167172
}

0 commit comments

Comments
 (0)
0