After updating to .NET Core 3 and latest NuGet package, I get the following error:
{
"Depth": 0,
"ClassName": "System.TypeInitializationException",
"Message": "The type initializer for 'NativeMagickSettings' threw an exception.",
"Source": "Magick.NET-Q8-AnyCPU",
"StackTraceString": " at ImageMagick.MagickSettings.NativeMagickSettings..ctor()\n at ImageMagick.MagickSettings..ctor()\n at ImageMagick.MagickImage..ctor()\n at ImageMagick.MagickImage..ctor(Stream stream)\n at Reshopper.Controllers.MediaController.RedirectToImage(String filePath) in /src/Reshopper/Controllers/MediaController.cs:line 31\n at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\n at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\n at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\n at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\n at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)\n at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)\n at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)\n at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)\n at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"HResult": -2146233036,
"HelpURL": null,
"innerException": {
"Depth": 1,
"ClassName": "System.DllNotFoundException",
"Message": "Unable to load shared library 'Magick.Native-Q8-x64.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libMagick.Native-Q8-x64.dll: No such file or directory",
"Source": "Magick.NET-Q8-AnyCPU",
"StackTraceString": " at ImageMagick.Environment.NativeMethods.X64.Environment_Initialize()\n at ImageMagick.Environment.NativeEnvironment.Initialize()\n at ImageMagick.Environment.Initialize()\n at ImageMagick.MagickSettings.NativeMagickSettings..cctor()",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"HResult": -2146233052,
"HelpURL": null
}
}
Is it possible to create a small sample application that demonstrates this issue? And on which platform are you getting this issue. Next time please enter the information requested in the issue template because that makes my life a lot easier.
It might be because I'm building and running it on Docker, via the mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine image.
I just don't know what image I should be using then.
Could you create a small sample repo that demonstrates this issue? A simple application that does something with Magick.NET and has a Dockerfile that uses that image.
I am using Magick.NET (albeit the Q16-HDRI) flavor in .NET Core 3.0 without error. So, most likely a deployment issue. There are some little hiccups here and there in building and deploying .NET Core 3.0 vs 2.0.
Have you been able to resolve this @ffMathy?
Nope, same issue. Even tried changing docker image. I can't share my source code unfortunately but there is nothing special about it.
I take a WEBP file and convert it to JPG. That's all.
Is it possible to trim your code down to a sample repository that demonstrates this issue?
Yes, but I don't have the time. I'm sure a sample asp.net core app using docker would demonstrate it though!
I had the same error using mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine, When I switch to mcr.microsoft.com/dotnet/core/aspnet:3.0 it works.
I think the alpine image lacks a package, but I don't know which one ...
Ah @seguins that solved it for me - thanks.
@dlemstra perhaps add it to the documentation to avoid future confusion?
@ffMathy: I have updated the title to make this more discoverable.
Thanks for the info @seguins.
This weekend support for linux-musl was added to the Magick.Native library and I just added support for it to Magick.NET. Starting with the next release you will be able to run this library on an alpine image.
alpine (docker image) uses musl libc and requires porting, for comparison see: https://www.etalabs.net/compare_libcs.html
A new release of Magick.NET that resolves this issue has been published.
For me it, this issue appeared again with the mcr.microsoft.com/dotnet/core/aspnet:5.0-alpine image.
I just ran a test to check if the native library works with that image and it seems to be working @furoTmark. This is probably something in your setup.
Most helpful comment
For me it, this issue appeared again with the mcr.microsoft.com/dotnet/core/aspnet:5.0-alpine image.