AWS Lambda Aspose.Cells exception

Hi Team,

Facing an exception while executing excel report generation using Aspose.Cells from AWS Lambda environment. The exception brief message is.

“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”

Environment details

  1. AWS Lambda
  2. Lambda runs docker image .NET6 code
  3. OS Amazon.Linux.2
  4. Aspose.Cells version 22.3.0

Workarounds tried
Included libgdiplus installation in dockerfile layer
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
RUN apt-get update && apt-get install -y libgdiplus

  1. I’m looking for possible out of box solution from Aspose, can Aspose.Drawing libs be used by Aspose.Cells which can eliminate the dependency on System.Drawing namespsace (which is not-compatible with linux os)?

  2. Any workarounds to be added in the dockerfile build to resolve the issue?

Please let me know your recommendations and suggestions at the earliest, appreciate your help.

Hi @rajkumar.vedhasiva
We did these following tests, for Aspose.cells for netstandard:
1, ASP.NET Core Web Application, deployed to AWS Elastic Beanstalk.
2, AWS Serverless project, deployed to AWS Lambda.
And we are sure Aspose.cells for netstandard can be used in these cases.

But in this case:
3, “AWS Lambda Function Project, deployed to AWS Lambda”, it will cause an error:
System.TypeInitializationException: The type initializer for ‘Gdip’ threw an exception. —> System.DllNotFoundException: Unable to load shared library ‘libgdiplus’ or one of its dependencies.

Reference link:

Please confirm what kind of situation your program is in and share a simple test program and docker file with us to help test it. Thank you.

And, right now Aspose.Cells can not use Aspose.Drawing libs, But we are testing this solution as part of the preparation for NET7.0.

Hi Leoluo,

Thanks for your response.

Here is our situation, we have two test-cases with Aspose.Cell one which works and another one fails.

The code which works.

Code snippet.

// When you create a new workbook, a default “Sheet1” is added to the workbook.
Worksheet sheet = wb.Worksheets[0];

// Access the “A1” cell in the sheet.
Cell cell1 = sheet.Cells[“A1”];
Cell cell2 = sheet.Cells[“A2”];

cell1.PutValue(DateTime.Now.ToString());
// Input the “Hello World!” text into the “A1” cell
cell2.PutValue($“Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!”);

// Save the Excel file.
byte[] fileContent;
using (MemoryStream myStream = new MemoryStream())
{
wb.Save(myStream, SaveFormat.Xlsx);
fileContent = myStream.ToArray();
}

The code which breaks.

Tried to invoke “this.ExcelWorkBook.Worksheets[i].AutoFitColumns();” ended up with following exception

MessageId: 3194a870-7c0c-4cba-9965-5ccb888383a1 - Exception: System.TypeInitializationException: The type initializer for ‘’ threw an exception.
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.GdipStringFormatGetGenericTypographic(IntPtr& format)
at System.Drawing.StringFormat.get_GenericTypographic()
at …cctor()
— End of inner exception stack trace —
at .(String , Font , Double )
at .(Int32 , Int32 , Int32 , Int32 , AutoFitterOptions )
at .(Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions )
at Aspose.Cells.Worksheet.AutoFitColumns()

Docker file

FROM public.ecr.aws/lambda/dotnet:6 AS base

FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
RUN apt-get update && apt-get install -y libgdiplus

COPY src /src
WORKDIR “/src/lambda_function”

RUN dotnet restore “lambda_function.csproj”
RUN dotnet build “lambda_function.csproj” --configuration Release --output /app/build -
FROM build AS publish
RUN dotnet publish “lambda_function.csproj”
–configuration Release \
–runtime linux-x64
–self-contained false \
–output /app/publish
-p:PublishReadyToRun=true

FROM base AS final
WORKDIR /var/task
COPY --from=publish /app/publish .

@rajkumar.vedhasiva,

Thanks for the details and docker file.

We will evaluate your issue and get back to you soon.

Hi @rajkumar.vedhasiva
I notice that the project you are using is: “lambda_function.csproj”,
I’m afraid, based on my previous tests, “libgdiplus” won’t work in the lambda_function project.

Some of your cases succeed because they don’t involve drawing, they don’t call libgdiplus, and when you execute “AutoFitColumns”, libgdiplus gets called, and it goes wrong.

For these problems, if want to solve thoroughly, there is no better way at present. Because Microsoft has stopped support for Libgdiplus on non-windows platforms.

We are also developing new support versions for this, eliminating reliance on system.drawing.common and libgdiplus on non-windows platforms. But it may take a period of time.

Do you know when “new support version to eliminate the dependency on System.Drawing.Common” will be available for development, any timelines?

Thank you for the details

@rajkumar.vedhasiva,

We will check if we could provide you an ETA on it but this is not going to be implemented/supported any time soon.

Ok, please share if you have an available ETA in future. Thank you.

@rajkumar.vedhasiva,

It is quite hard to give an ETA at the moment. We have also logged a ticket (regarding eliminate dependencies of System.Drawing.Common and libgdiplus on non-Windows platforms for lambda_function project) for it and attached the ticket id with the thread, so you will be notified once we have an ETA on it or have some other updates on it.

Hi @rajkumar.vedhasiva
We released Aspose.Cells version that uses skiasharp, to resolve the problem that “libgdiplus” does not work well in AWS Lambda.
You can refer to the documentation below for the new version.

Thank you leoluo. I started to use skiasharp libs and its producing desired results in linux based workloads.

@rajkumar.vedhasiva,

That’s great! It’s nice to know that using Aspose.Cells with SkiaSharp works for your needs. If you have any further queries or issues, feel free to write back to us.

The issues you have found earlier (filed as CELLSNETCORE-380) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi