We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Cells .NET6 saving workbook as PDF fails on Linux


I have a .NET6 app with Aspose cells 22.5.0. It works great on windows machine but fails with following error when saving a workbook as PDF:

Aspose.Cells.CellsException: The type initializer for ' ’ threw an exception. at Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions)

image.png (2.4 KB)
(The exception message above is not correctly displayed)

This is line its failing on: workbook.Save(memoryStream, SaveFormat.Pdf);

I tried the following code:

    public async Task<ActionResult> Test1()
        Workbook workbook = new Workbook();

        workbook.Worksheets[0].Cells[0, 0].PutValue("Hello from Aspose.Cells!!!");

        var ms = new MemoryStream();

        workbook.Save(ms, SaveFormat.Pdf);

        ms.Position = 0;

        return File(ms, "application/pdf");

If I replace the output format PDF with e.g. XLS, it works on the linux machine as well.

Runtime Environment:
.NET Core SDK Version: 6.0.301
CentOS Linux release 7.9.2009 (Core)

I have installed the latest version of libgdiplus using
yum install libgdiplus

Please let me know if you need more details.


Thank you for your query.

We did test such a scenario on Ubuntu 16.04 x64, in a docker container.
Here are our steps:

The docker we use is: microsoft/dotnet, install it first:
sudo docker pull microsoft/dotnet

Then, after running it, if we run this issue in this docker, we get the error:

Aspose.Cells.CellsException : The type initializer for ‘???’ threw an exception.
at Aspose.Cells.Workbook.Save(String fileName, SaveOptions saveOptions)

It seems to be the same error you also get.

Then we install libgdiplus using the command lines:

apt-get update
apt-get install -y libgdiplus
cd /usr/lib && ln -s libgdiplus.so gdiplus.dll

And then install libc6-dev:
apt-get install -y --no-install-recommends libc6-dev

After all these steps, the issue passed, and the PDF file created successfully.
Would you please check it and share the feedback?

Thank you for your reply.

I run the app under CentOS 7.9 (which is a supported OS accoring to https://docs.aspose.com/cells/net/system-requirements/#linux) and thus I executed the following commands:

yum install libgdiplus
yum install glibc-devel
ln -s /usr/lib64/libgdiplus.so.0.0.0 /usr/lib/gdiplus.dll
ln -s /usr/lib64/libgdiplus.so.0.0.0 /usr/lib64/gdiplus.dll

Unfortunately the error while saving the workbook als PDF still occurs.

Please let me know if you need more details.


Thanks for providing further details.

We have logged a ticket with an id “CELLSNETCORE-396” to investigate your issue. We will look into it soon. Once we have an update on it, we will let you know.

Hi @Alex2000
It need to draw a picture to save a PDF, but need not when save as XLS. I think the Graphics Library is not installed properly.

1, Confirm system.drawing.common can run properly, such as:

        Bitmap image = new Bitmap(100, 100);
        Graphics g = Graphics.FromImage(image);

Can you run above code successful in your environment? (just refer to system.drawing.common)

2, Make sure the “EnableUnixSupport” switch is turned on, see:

@leoluo @Amjad_Sahi
Thank you for your reply.

Turning on the switch EnableUnixSupport resolved the issue.

Both the PDF generation and your bitmap sample code worked after setting EnableUnixSupport to true. It would be nice to include this or some other workaround for .NET6+ in the Aspose documentation, as this might become a common issue.


Good to know that the suggested configuration works for your needs for now.

We will check if we could include this tip or other useful information in the docs.

Hi @Alex2000
Thanks for your suggestion, we think it is necessary and have added a note to the document:
Getting Started|Documentation (aspose.com)