Unable to load shared library 'libgdiplus'

Hi,

We are having an issue on our .NET service (ASP.NET service with .NET Core 6.0 - we create a docker that runs on Azure cloud as a kubernetes pod).

We get the following exception in several scenarios:

---- 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
  1. Calling AutoFitColumns
  2. Initiating Aspose.Slides.Presenation object

Please see how our Docker file is configured: Dockerfile.zip (550 Bytes)

I saw that there are few tickets on this matter, I didn’t find a solution for our issue there. hopefully there is a way to modify our Docker file to fix this matter.

Thanks in advance,
Ori

@orik,

Thanks for the docker file.

I guess some of your test cases would be succeeded which do not involve drawings as they don’t call libgdiplus library. But some cases won’t work which involve drawings or graphics. For example, when you execute “AutoFitColumns” operation, libgdiplus gets called and you got the issue.

We are afraid, to solve your issue thoroughly, there is no better way currently. The reason is Microsoft has stopped support for Libgdiplus on non-Windows platforms. We will develop (new) supported versions for such issues and will eliminate dependencies of System.Drawing.Common and libgdiplus on non-Windows platforms. But since it involves complexities so this is not going to be implemented/supported any time soon.

Please post your issue/query in Aspose.Slides forum, one of our fellow colleagues from Aspose.Slides team will assist you soon there.

Hi @Amjad_Sahi thank you for your quick response.

I have two questions:

  1. when you are saying “not going to be implemented/supported any time soon.” - are we talking on weeks? months? or even more?
  2. Theoretically, if I could run my Docker on windows platform, we are not supposed to have these issues, is this correct?
    Do you have a other recommendation or best practices we should adopt in order to have an instant solution?

Thanks in advance,
Ori

@orik,

  1. We think we have to get rid of Libgdiplus to solve such problems. We decide to use Aspose.Drawing for Aspose.Cells to test and evaluate issues on Linux or non-Windows platforms. Our plan is to implement in sync when the official version of .NET 7 is released by Microsoft.

  2. You know Azure has some special sandbox mechanisms, so we cannot say that solutions that are available on Windows Docker are available in Azure.

Hi orik,
Dealing with the same issue here working in .Net 5 under docker container in Ubuntu 20.04:
A work-around for me was to add a runtimeconfig.template.json file to my project with this content:
{
“configProperties”: {
“System.Drawing.EnableUnixSupport”: true
}
}

This got rid of the TypeInitializationException. Not sure how long this workaround will last though…

gr, Peter

@Amjad_Sahi, @peterdewachtere
Thank you for your answers.

So what we’ll need to understand is what is your suggestion for the short term?
As we understand, .NET 7 will be released only by the end of 2022 and we cannot afford waiting so long.

The two option I see now are

  • Explore windows Dockers solution
  • Move to .NET 5

Do we have other options ?

Please advice.
Thanks !
Ori

UPDATE:
I’ve tried migrating the service to .NET 5 and this didn’t resolve the issue, I’m getting the same errors

I am afraid, there is no better option/way to cope with it until .NET7 is released. Anyways, if we found some better way, we will share it with you.

@orik,
We have tested CentOS 7 with .NET Core 6.0 and found no exceptions. The attachment is our test project, which contains a dockfile. You can deploy it for testing. If you can find exceptions, there may be a problem with your platform. If there is no abnormality, please send us the project you found abnormal. It’s best to upload a simple test project. WebApp1.zip (7.6 MB)

Hi John,
I am also getting same exception, Can you please provide me access to WebApp1.zip, I am not able to download it.

@udaymishra,

Since you are not the owner of the thread, so you might not download the attachments shared in this thread. To get “WebApp1.zip”, please create a new thread (please refer to this thread’s attachment (which you want)) and ask for the zipped archive. We will then provide you the attachment in your thread.

Is there any resolution to this?

Failed ConvertHtmlToPDF_success [4 s]
13:08:10 Error Message:
13:08:10 System.TypeInitializationException : The type initializer for ‘Gdip’ threw an exception.
13:08:10 ----> 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
13:08:10 Stack Trace:
13:08:10 at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix2(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy, IntPtr& matrix)
13:08:10 at #=zA8nUNJDbrXJBRX1YabeyDt2XThIOpPBkig==.#=zQImv8QoE_aK9rThIWirOd48=(SizeF #=zn3pLiPM=)
13:08:10 at #=zA8nUNJDbrXJBRX1YabeyDt2XThIOpPBkig==.#=z2X9sAbY=(SizeF #=zn3pLiPM=)
13:08:10 at #=zTGWPsk3D8hcgYuoVd4ZJFayAmfv92H4LAA==.Render(#=zcA5tkB2Xv5iTqtZ5df5CmVbRvpJB #=zGiPwQn8=)
13:08:10 at #=zdmQGaJtN8uv2uI_l$JUM$cpy4mhYvtmpzw==.#=zCxkQlGtsndLC(#=zeqBIS9hneXY7Njgi8nZUs1A= #=zDr1u$H1kR$pdHKR12Q==, #=zv82HhNzJ2eBZCmpF9Va1MtYXoy5v[] #=zssOFcJiteEa2, #=zcA5tkB2Xv5iTqtZ5df5CmVbRvpJB #=zGiPwQn8=, TimeSpan #=z95GV29I=)

@vinayakbaddi6,

Aspose.Cells now also provides .NET6.0 library that uses SkiaSharp as the graphics library, as recommended in official statement of Microsoft. For more details about using Aspose.Cells with NET6, please see the document on how to use and run Aspose.Cells for .NET6.0.

Please try using our latest version/fix: Aspose.Cells for .NET v22.12 (Releases | NuGet).

Kindly help with Reference to Aspose.PDF for solution.

@vinayakbaddi6,

Please post your query/issue in Aspose.PDF forum, one of our colleagues from Aspose.PDF team will assist you there.