Skip to content

Commit

Permalink
Changing to dll loading to absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekctek committed Apr 26, 2023
1 parent 45f9e1a commit 9b9fc3f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/EdjCase.Cryptography.BLS/NativeInterop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

Expand All @@ -26,6 +29,7 @@ public static IntPtr LoadNativeLibrary(string libraryName)
{
IntPtr libraryHandle;

string basePath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string? runtime = null;
Expand All @@ -34,15 +38,12 @@ public static IntPtr LoadNativeLibrary(string libraryName)
case Architecture.X64:
runtime = "win-x64";
break;
case Architecture.Arm64:
runtime = "win-arm64";
break;
}
if (runtime == null)
{
throw new NotImplementedException($"OS '{RuntimeInformation.OSDescription}' and architecture '{RuntimeInformation.OSArchitecture}' is not yet supported");
}
libraryHandle = LoadLibrary($"runtimes/{runtime}/native/" + libraryName);
libraryHandle = LoadLibrary($"{basePath}/runtimes/{runtime}/native/" + libraryName);
}
else
{
Expand Down Expand Up @@ -75,7 +76,7 @@ public static IntPtr LoadNativeLibrary(string libraryName)
{
throw new NotImplementedException($"OS '{RuntimeInformation.OSDescription}' and architecture '{RuntimeInformation.OSArchitecture}' is not yet supported");
}
libraryHandle = dlopen($"runtimes/{runtime}/native/" + libraryName, RtldNow);
libraryHandle = dlopen($"{basePath}/runtimes/{runtime}/native/" + libraryName, RtldNow);
}

if (libraryHandle == IntPtr.Zero)
Expand Down

0 comments on commit 9b9fc3f

Please sign in to comment.