Aspose PDF library throwing - Unhandled exception. System.TypeLoadException: Cannot load type 'System.Void, mscorlib...' while running in Docker container

'm getting this exception

“Unhandled exception. System.TypeLoadException: Cannot load type ‘System.Void, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.”

While using Aspose PDF in our QA env, which is dockerized from the base images “dotnet/sdk:6.0-alpine” and “dotnet/runtime-deps:6.0-alpine” .

Is there any compatibility issue between these images and Aspose?

Aspose Library version: 22.12.0 (Even tried with 23.1.0)

NOTE: This is only occurring in QA environment where we have dockerized the application, but working fine in Dev environment where no Dockerization happening.

I tried some fixes like using Aspose.Pdf.Drawing instead of Aspose.Pdf based on some guidance. But it keeps failing with the above exception.

FYI:
sample.pdf (3.0 KB)

.NET version : 6.0
Docker Build and runtime base images: “dotnet/sdk:6.0-alpine” and “dotnet/runtime-deps:6.0-alpine” .

In my case, I tried to create a Aspose.Pdf.Document from the attached PDF document.

Please note, I can’t directly attach the dockerfile here as it contains in a client laptop which can’t be transferred. But I can give more info if needed.

@sreeraj1237

An investigation ticket as following has been logged in our issue tracking system for further investigation against your scenario. We will look into its details and let you know as soon as it is resolved. Please be patient and spare us some time.

Issue ID(s): PDFNET-53753

We are sorry for the inconvenience.

Thanks @asad.ali. Just FYI, This issue we are observing in multiple places like setting license.
License.SetLicense(…)

@sreeraj1237

Is it possible that you could provide a sample console application that is able to reproduce the same issue in our environment? Also, please make sure that libgdiplus package is properly installed and updated in the system where such error is occurring.

This issue is fixed in our environment. The rootcause was the dotnet publish options present in the Dockerfile. PublishTrimmer=true, which trimmed some required classes which required for Aspose to run it seems.
Started working once we removed this parameter.

Thanks for your help and time.

@sreeraj1237

It is nice to hear that your issue has been resolved. Please feel free to create a new topic in case you need further assistance.