Skip to content

Commit

Permalink
Fix Windows to look in Assembly Directory for 32bit dll.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dellis1972 committed Aug 6, 2020
1 parent b332af0 commit fdabcda
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion LibZipSharp.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LibZipSharpNugetVersion>1.0.17</_LibZipSharpNugetVersion>
<_LibZipSharpNugetVersion>1.0.18</_LibZipSharpNugetVersion>
</PropertyGroup>
</Project>
4 changes: 1 addition & 3 deletions Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit fdabcda

Please sign in to comment.