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:
[HttpGet("test1")]
[AllowAnonymous]
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.
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:
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.
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.