我刚刚尝试在我的 C# 项目中使用 Magick.NET (Q16, AnyCpu)。我通过 Monodevelop 中的 nuget 安装它(我在 linux 上),并尝试使用以下代码在我的项目中对其进行测试:
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();
...但我在第一行遇到了一个例外。奇怪的。这是堆栈跟踪的相关部分:
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
...
这里发生了什么?