.Net Core System.Drawing error with AWS Lambda

我的未来我决定 提交于 2021-02-10 20:45:10

问题


I am trying to generate a QRCode using .Net Core with AWS Lambda. But it seems there is an issue using System.Drawing libraries with lambda. Everything works fine until I start using any System.Drawing functions. This question has been asked before but there does not seem to be any good solutions. Here is the code I have currently in the controller:

    QRCodeGenerator qrGenerator = new QRCodeGenerator();
    QRCodeData qrCodeData = qrGenerator.CreateQrCode("hello", QRCodeGenerator.ECCLevel.Q);
    QRCode qrCode = new QRCode(qrCodeData); //works till here. Commented below does not work.
    //Bitmap qrCodeImageBitMap = qrCode.GetGraphic(20);
    List<string> testing = new List<string>();
    testing.Add("added");
    return Ok(testing);

Here is part of the error found in the CloudWatch logs:

[Error] Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction: Unknown error responding to request: TypeInitializationException:
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory
at Interop.Libdl.dlopen(String fileName, Int32 flag)
at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0...

How do I make System.Drawing work with lambda? I don't think there are alternate libraries available as I require drawing functionality. I am also using QRCoder library from https://github.com/codebude/QRCoder but that does not cause any problems.

来源:https://stackoverflow.com/questions/52762988/net-core-system-drawing-error-with-aws-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!