1

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.

  • I have the same [question](https://stackoverflow.com/questions/50615704/unable-to-load-dll-libdl-when-using-system-drawing-common-nuget-package-on-aws). This is very frustrating. – ProgrammingLlama Nov 02 '18 at 00:59
  • @John it seems there is no fix to this. What I did was to write the function using node.js. There were no compatibility issues there. It is unfortunate that .Net Core has this problem. – Avinash Prabhakar Nov 02 '18 at 12:24
  • We need a QR generator library that does not use System.Drawing – Rez.Net Jul 31 '20 at 21:48

0 Answers0