AWS Lambda Exception: Unable to load shared library 'libSkiaSharp'

When calling document.Save() as PNG in an AWS Lambda the code fails with the below exception

{
  "errorType": "AggregateException",
  "errorMessage": "One or more errors occurred. (The type initializer for '\u0002  ' threw an exception.)",
  "stackTrace": [
    "at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
    "at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
  ],
  "cause": {
    "errorType": "TypeInitializationException",
    "errorMessage": "The type initializer for '\u0002  ' threw an exception.",
    "stackTrace": [
      "at \b​  .\u0002()",
      "at \b​  .\u0002(Stream \u0002)",
      "at \u0005​  .\u0005​   ​​\u0002(\u0003    \u0002)",
      "at \u000f   .\u000f    ​​\u0002(\u0003    \u0002)",
      "at Aspose.Words.Document.\u0002(\u0003    \u0002, SaveOptions \u0003)",
      "at Aspose.Words.Document.\u0002(Stream \u0002, String \u0003, SaveOptions \u0005)",
      "at OfficeDocToImage.Function.ConvertWordToImages(AmazonS3Client client, GetObjectResponse response, String s3Folder, String s3Bucket, OfficeDocToImageRequest request) in /.../udmOfficeDocToImage/src/OfficeDocToImage/Function.cs:line 148",
      "at OfficeDocToImage.Function.FunctionHandler(APIGatewayProxyRequest apiRequest, ILambdaContext context) in /.../udmOfficeDocToImage/src/OfficeDocToImage/Function.cs:line 72"
    ],
    "cause": {
      "errorType": "TypeInitializationException",
      "errorMessage": "The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.",
      "stackTrace": [
        "at SkiaSharp.SKBitmap..ctor(Int32 width, Int32 height, Boolean isOpaque)",
        "at \u0002  ..cctor()"
      ],
      "cause": {
        "errorType": "DllNotFoundException",
        "errorMessage": "Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory",
        "stackTrace": [
          "at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()",
          "at SkiaSharp.SKImageInfo..cctor()"
        ]
      }
    }
  },
  "causes": [
    {
      "errorType": "TypeInitializationException",
      "errorMessage": "The type initializer for '\u0002  ' threw an exception.",
      "stackTrace": [
        "at \b​  .\u0002()",
        "at \b​  .\u0002(Stream \u0002)",
        "at \u0005​  .\u0005​   ​​\u0002(\u0003    \u0002)",
        "at \u000f   .\u000f    ​​\u0002(\u0003    \u0002)",
        "at Aspose.Words.Document.\u0002(\u0003    \u0002, SaveOptions \u0003)",
        "at Aspose.Words.Document.\u0002(Stream \u0002, String \u0003, SaveOptions \u0005)",
        "at OfficeDocToImage.Function.ConvertWordToImages(AmazonS3Client client, GetObjectResponse response, String s3Folder, String s3Bucket, OfficeDocToImageRequest request) in /.../udmOfficeDocToImage/src/OfficeDocToImage/Function.cs:line 148",
        "at OfficeDocToImage.Function.FunctionHandler(APIGatewayProxyRequest apiRequest, ILambdaContext context) in /.../udmOfficeDocToImage/src/OfficeDocToImage/Function.cs:line 72"
      ],
      "cause": {
        "errorType": "TypeInitializationException",
        "errorMessage": "The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.",
        "stackTrace": [
          "at SkiaSharp.SKBitmap..ctor(Int32 width, Int32 height, Boolean isOpaque)",
          "at \u0002  ..cctor()"
        ],
        "cause": {
          "errorType": "DllNotFoundException",
          "errorMessage": "Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory",
          "stackTrace": [
            "at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()",
            "at SkiaSharp.SKImageInfo..cctor()"
          ]
        }
      }
    }
  ]
}

@deanvniekerk

Please note that .NET Standard 2.0 version of Aspose.Words uses SkiaSharp to deal with graphics. SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google’s Skia Graphics Library.

Could you please share your working environment e.g operating system, .NET version etc.

Hi,

The code is running in an AWS lambda, the environment is an Amazon Linux image.

@deanvniekerk

You need to add reference of SkiaSharp.NativeAssets.Linux to your application. We suggest you please read the following article.

How to Run Aspose.Words Docker