dlemstra / Magick.NET

The .NET library for ImageMagick
Apache License 2.0
3.42k stars 413 forks source link

Unable to load DLL 'Magick.NET-Q16-x86.Native.dll': The specified module could not be found #1198

Closed ipoweb closed 2 years ago

ipoweb commented 2 years ago

Magick.NET version

11.2.0

Environment (Operating system, version and so on)

Windows 10 64 bits, IIS 10

Description

I used nugget package Magick.net-Q16-AnyCPU with IIS and Application Pool "NET v4.5" - Pipeline Integrated with advanced Parameters "Enable 32 bits applications" on True for Web Application

After building with Debug Mod in Visual studio 2022 with AnyCPU, i get this error

{"Unable to load DLL 'Magick.Native-Q16-x86.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"}

I check in my bin folder and find only Magick.NET-Q16-AnyCPU.dll Magick.NET.Core.dll

Steps to Reproduce

I have confirmed the dlls in bin folder of deployed project are release for 👍 Magick.NET-Q16-AnyCPU.dll Magick.NET.Core.dll but not for Magick.NET-Q16-x86.Native.dll

dlemstra commented 2 years ago

The Magick.NET-Q16-x86.Native.dll library should be copied to your bin folder but for some reason this is not happening with your project. This must be something in your local project setup and I cannot assist you with that. A possible workaround would be that you copy the library from the NuGet package to your bin folder manually.

ipoweb commented 2 years ago

Thanks for your answer, in past no problem with Magick.NET 8.5, do you think it's problem with last version ?

dlemstra commented 2 years ago

There have been a lot of changes in the library and one of them is that support for .NET 2.0 was removed from they AnyCPU version. Is the netstandard20 version or the netstandard21 version used? I am assuming you have an old .csproj format with a packages.config file?

sescandell commented 2 years ago

@sireneweb we had the same issue moving from 8.x to the latest version. Here is how we fixed it.

Our context was the following:

The key thing is the Nuget is referenced by a sub-project. So the targets file is not included by itself in the csproj. So, to make our MVC Web project work as expected, I had to manually add the following in the Web.csproj:

<!-- If you want help in the build console -->
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. {1}</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(NuGetPackageRoot)Magick.NET-Q16-AnyCPU\11.2.1\build\netstandard20\Magick.NET-Q16-AnyCPU.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)Magick.NET-Q16-AnyCPU\11.2.1\build\netstandard20\Magick.NET-Q16-AnyCPU.targets',
    '$(NuGetPackageRoot)'))" />
  </Target>
<!-- Import the project target file so DLL is automatically copied -->
<Import Project="$(NuGetPackageRoot)Magick.NET-Q16-AnyCPU\11.2.1\build\netstandard20\Magick.NET-Q16-AnyCPU.targets" />

We do not have the same issue with a "Web project" targetting aspnetcore or .net6

Hope that helps,