From fdabcda2528fc288ca13599274cd7f958b037ec6 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 6 Aug 2020 09:20:43 +0100 Subject: [PATCH] Fix Windows to look in Assembly Directory for 32bit dll. Commit 96eb5e34 introduced the use of `DefaultDllImportSearchPathsAttribute` to add extra security when loading native libraries. This works fine when the executable that is running is in the same directory as the `LibZipSharp.dll` and the `libzip.dll`. However when the executable has a different `WorkingDirectory` as the `LibZipSharp.dll` this then causes the following error. System.DllNotFoundException: Unable to load DLL 'libzip' This is because with the new attribute only Safe paths are searched. So when we run this under MSBuild.exe for example, the `Working` directory will definately NOT contain the 32bit `libzip.dll`. The fix to to always set the location of the `libzip.dll` via `SetDllDirectory` for both 32bit and 64bit processes. Also bump to 1.0.18 --- LibZipSharp.props | 2 +- Native.cs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/LibZipSharp.props b/LibZipSharp.props index 7f740c6a..8abf71e0 100644 --- a/LibZipSharp.props +++ b/LibZipSharp.props @@ -1,5 +1,5 @@ - <_LibZipSharpNugetVersion>1.0.17 + <_LibZipSharpNugetVersion>1.0.18 diff --git a/Native.cs b/Native.cs index 54ffd482..ada88853 100644 --- a/Native.cs +++ b/Native.cs @@ -415,9 +415,7 @@ static Native () { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { string executingDirectory = System.IO.Path.GetDirectoryName (typeof(Native).Assembly.Location); - if (Environment.Is64BitProcess) { - SetDllDirectory (System.IO.Path.Combine (executingDirectory, "lib64")); - } + SetDllDirectory (Environment.Is64BitProcess ? System.IO.Path.Combine (executingDirectory, "lib64") : executingDirectory); } } }