Skip to content

NativeMethods.ResolveDll: Avoid exceptions #1741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,17 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
// The <rid> ends with the processor architecture. e.g. fedora-x64.
string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location);
string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
foreach (var runtimeFolder in Directory.GetDirectories(Path.Combine(assemblyDirectory, "runtimes"), $"*-{processorArchitecture}"))
string runtimesDirectory = Path.Combine(assemblyDirectory, "runtimes");

if (Directory.Exists(runtimesDirectory))
{
string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so");
if (TryLoadLibrary(libPath, out handle))
foreach (var runtimeFolder in Directory.GetDirectories(runtimesDirectory, $"*-{processorArchitecture}"))
{
return handle;
string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so");
if (TryLoadLibrary(libPath, out handle))
{
return handle;
}
}
}
}
Expand Down