.NET Core cannot find libgdiplus when using System.Drawing.Common

 

Problem: .NET Core cannot find libgdiplus when using System.Drawing.Common

Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]

An unhandled exception has occurred while executing the request.

System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.

---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgdiplus: cannot open shared object file: No such file or directory

at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)

at System.Drawing.SafeNativeMethods.Gdip..cctor()

--- End of inner exception stack trace ---

at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, HandleRef scan0, IntPtr& bitmap)

at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)

at CS.FTX.Web.Common.Extions.GetSecurityCode(String& code) in E:\Source\DotNetCore\CS.FTX\CS.FTX.Web\Common\Extions.cs:line 56

at CS.FTX.Web.Controllers.AccountController.SecurityCode() in E:\Source\DotNetCore\CS.FTX\CS.FTX.Web\Controllers\AccountController.cs:line 201

at lambda_method(Closure , Object , Object[] )

at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

--- End of stack trace from previous location where exception was thrown ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()

--- End of stack trace from previous location where exception was thrown ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()

--- End of stack trace from previous location where exception was thrown ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)

at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)

at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)

at CS.FTX.Web.Common.RequiredAdminMiddleware.InvokeAsync(HttpContext context, IHttpContextAccessor httpContextAccessor) in E:\Source\DotNetCore\CS.FTX\CS.FTX.Web\Common\RequiredAdminMiddleware.cs:line 54

at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)

at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)

at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)

at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)

at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator)

at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)

at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)

at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

 

 

 

 

solve:

https://q.cnblogs.com/q/109061/

 

Install libc6-dev in addition to libgdiplus

 

apt-get update

apt-get install -y --no-install-recommends libgdiplus libc6-dev ‘

 

 

 

analyze:

Why can't I find libdl (libdl.so.2)?

It is because System.Drawing.Common is found in the path /usr/lib/x86_64-linux-gnu/, and libdl.so.2 in the container exists in the /lib/x86_64-linux-gnu/ directory,

After installing libc6-dev, there is libdl.so.2 in /lib/x86_64-linux-gnu/, and the problem is solved.

No need for ln -s libgdiplus.so gdiplus.dll now, System.Drawing.Common has changed the code to load libgdiplus.so directly 

 

 

Disclaimer: This question is a record of the pit, and the reference materials are as follows

https://q.cnblogs.com/q/109061/

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324328986&siteId=291194637