Search code examples
c#imagemagickmagick.netinitialization

Can't use Magick.NET: System.EntryPointNotFoundException


I've just been attempting to use Magick.NET (Q16, AnyCpu) in my C# project. I installed it via nuget in Monodevelop (I'm on linux), and attempted to test it in my project with this code:

using ImageMagick;

// ...

MagickImage img = new MagickImage(requestedPath);
img.Thumbnail(new MagickGeometry(thumbnailWidth, thumbnailHeight));
cycle.Response.ContentType = "image/webp";
img.Write(httpContext.Response.OutputStream, MagickFormat.WebP);
img.Dispose();

...but I got an exception on the first line. Odd. Here's the relevant part of the stack trace:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'X64' threw an exception. ---> System.EntryPointNotFoundException: SetDllDirectory
  at (wrapper managed-to-native) ImageMagick.NativeLibraryLoader+NativeMethods:SetDllDirectory (string)
  at ImageMagick.NativeLibraryLoader.ExtractLibrary () <0x4089f680 + 0x0009b> in <filename unknown>:0 
  at ImageMagick.NativeLibraryLoader.Load () <0x4089f640 + 0x00027> in <filename unknown>:0 
  at ImageMagick.MagickSettings+NativeMethods+X64..cctor () <0x4089f530 + 0x0000b> in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at ImageMagick.MagickSettings+NativeMagickSettings..ctor () <0x4089f3e0 + 0x00017> in <filename unknown>:0 
  at ImageMagick.MagickSettings..ctor () <0x4089efb0 + 0x000a7> in <filename unknown>:0 
  at ImageMagick.MagickImage..ctor () <0x4089eee0 + 0x00033> in <filename unknown>:0 
  at ImageMagick.MagickImage..ctor (System.String fileName) <0x4089ee90 + 0x00017> in <filename unknown>:0 
...

What's going on here?


Solution

  • Magick.NET only works on Windows at the moment. There are plans to add support for Linux in the .NET Core version of Magick.NET. At the time of writing it is unknown when that will happen.

    EDIT: Support for Linux has been added. Support for Mac is still on the todo list.