Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.DllNotFoundException: 'Unable to load DLL 'libvips-42.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)' #136

Closed
pablo-01 opened this issue Aug 27, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@pablo-01
Copy link

Hi,

I could use some help setting up Net-Vips on Windows (Visual Studio) for .Net Framework 4.6.1.
I have tried Net-Vips before with .NET 5 on Linux and it worked flawlesly.

When I install NetVips 2.0.1 (.NET bindings for libvips) and then NetVips.Native 8.11.3 from NuGet and run my test application it throws:

System.DllNotFoundException: 'Unable to load DLL 'libvips-42.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

I have tried to install the NuGet packages in various orders, also to try install the x86 and x64 separately but nothing helped.

I'd appreciate some advice on making this work. Thanks.

@hey-red
Copy link

hey-red commented Aug 28, 2021

I'm create console app for .NET 4.6.1

namespace NetVipsTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            if (ModuleInitializer.VipsInitialized)
            {
                Console.WriteLine($"Inited libvips {NetVips.NetVips.Version(0)}.{NetVips.NetVips.Version(1)}.{NetVips.NetVips.Version(2)}");
            }
            else
            {
                Console.WriteLine(ModuleInitializer.Exception.Message);
            }
            Console.ReadLine();
        }
    }
}

and it's works fine. All required dlls copied into destination directory.

example

kleisauke added a commit that referenced this issue Aug 28, 2021
Somehow the `<Link>` XML-element in the .targets file will no
longer default to `%(Filename)%(Extension)` when the
`LibvipsOutputBase` property is not set.
@kleisauke kleisauke added the bug Something isn't working label Aug 28, 2021
@kleisauke
Copy link
Owner

kleisauke commented Aug 28, 2021

I could reproduce this when building with .NET Framework v4.5 and v4.6.1. It looks like this <Link Condition=... XML-element in the .targets file will no longer default to %(Filename)%(Extension) when the LibvipsOutputBase property is not set.

<Link Condition="'$(LibvipsOutputBase)' != ''">$(LibvipsOutputBase)\%(Filename)%(Extension)</Link>

This prevents the native DLL files from being copied to the output directory when building with .NET Framework. On .NET Core, this is not needed at all, so that should work fine, as you've noticed.

The strange thing about this is that it did work in the past, so I think a recent MSBuild or NuGet upgrade broke this. FWIW, I couldn't reproduce this using this example project file (which should do the same thing as the specific .targets file).

ConsoleApp1.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <!-- <LibvipsOutputBase>x64</LibvipsOutputBase> -->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NetVips.Native.win-x64" Version="8.11.3" GeneratePathProperty="true" IncludeAssets="none" />
  </ItemGroup>

  <ItemGroup>
    <None Include="$(PkgNetVips_Native_win-x64)\runtimes\win-x64\native\*">
      <Link Condition="'$(LibvipsOutputBase)' != ''">$(LibvipsOutputBase)\%(Filename)%(Extension)</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

Fortunately, there's a way to workaround this by setting LibvipsOutputBase to . in your project file. For example:

<PropertyGroup>
  <LibvipsOutputBase>.</LibvipsOutputBase>
</PropertyGroup>

Commit 9fba9cc should also fix this. If you want to test this, you can use the nightly version of NetVips.Native. Add the https://ci.appveyor.com/nuget/net-vips feed in the <packageSources> section of your NuGet.config:

<packageSources>
  <add key="netvips-nightly" value="https://ci.appveyor.com/nuget/net-vips" />
</packageSources>

And use NetVips.Native v8.11.3 from there (make sure you've cleared your NuGet cache, since it has the same version number). I'll make a new release soon.

@pablo-01
Copy link
Author

@kleisauke thank you for fast reply and comprehensive instructions on how to fix this. I will try this on Monday and will report back. Many thanks.

@kleisauke
Copy link
Owner

NetVips.Native v8.11.3.1 is now available with this fix included. Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants