From 9c49d10d275bb3e4d471c65501f7f44d124d5a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B2=D0=B0=D1=81=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD?= Date: Thu, 18 Oct 2018 16:48:44 +0300 Subject: [PATCH] Fix native library probing under .net core --- Zstandard.Net/ZstandardInterop.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Zstandard.Net/ZstandardInterop.cs b/Zstandard.Net/ZstandardInterop.cs index 348e993..8e4d82e 100644 --- a/Zstandard.Net/ZstandardInterop.cs +++ b/Zstandard.Net/ZstandardInterop.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Runtime.InteropServices; @@ -13,7 +13,14 @@ static ZstandardInterop() var root = Path.GetDirectoryName(typeof(ZstandardInterop).Assembly.Location); var path = Environment.Is64BitProcess ? "x64" : "x86"; var file = Path.Combine(root, path, "libzstd.dll"); - LoadLibraryEx(file, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR); + var handle = LoadLibraryEx(file, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR); + if (handle == IntPtr.Zero) + { + //if we are running under .net core we may be located in nuget cache + //in that case probe application directory + LoadLibraryEx(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path, "libzstd.dll"), + IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR); + } } }