Skip to content

Commit fdabcda

Browse files
committed
Fix Windows to look in Assembly Directory for 32bit dll.
Commit 96eb5e3 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
1 parent b332af0 commit fdabcda

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

‎LibZipSharp.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ProjectDefaultTargets="Build"ToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3-
<_LibZipSharpNugetVersion>1.0.17</_LibZipSharpNugetVersion>
3+
<_LibZipSharpNugetVersion>1.0.18</_LibZipSharpNugetVersion>
44
</PropertyGroup>
55
</Project>

‎Native.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,7 @@ static Native ()
415415
{
416416
if(Environment.OSVersion.Platform==PlatformID.Win32NT){
417417
stringexecutingDirectory=System.IO.Path.GetDirectoryName(typeof(Native).Assembly.Location);
418-
if(Environment.Is64BitProcess){
419-
SetDllDirectory(System.IO.Path.Combine(executingDirectory,"lib64"));
420-
}
418+
SetDllDirectory(Environment.Is64BitProcess?System.IO.Path.Combine(executingDirectory,"lib64"):executingDirectory);
421419
}
422420
}
423421
}

0 commit comments

Comments
 (0)