Unable to load shared library 'libgdiplus' or one of its dependencies

We are developing a Google Cloud function using Aspose.Html library for .NET and when executing the line Converter.ConvertHTML() we are receiving the following error:

"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 using a tool like strace. If you’re using glibc, consider setting the LD_DEBUG environment variable:

/layers/google.dotnet.publish/publish/bin/runtimes/linux-x64/native/libgdiplus.so: cannot open shared object file: No such file or directory

/layers/google.dotnet.runtime/runtime/shared/Microsoft.NETCore.App/8.0.10/libgdiplus.so: cannot open shared object file: No such file or directory

/layers/google.dotnet.publish/publish/bin/runtimes/unix/lib/netcoreapp3.0/libgdiplus.so: cannot open shared object file: No such file or directory

/layers/google.dotnet.publish/publish/bin/runtimes/linux-x64/native/liblibgdiplus.so: cannot open shared object file: No such file or directory

/layers/google.dotnet.runtime/runtime/shared/Microsoft.NETCore.App/8.0.10/liblibgdiplus.so: cannot open shared object file: No such file or directory

/layers/google.dotnet.publish/publish/bin/runtimes/unix/lib/netcoreapp3.0/liblibgdiplus.so: cannot open shared object file: No such file or directory

/layers/google.dotnet.publish/publish/bin/runtimes/linux-x64/native/libgdiplus: cannot open shared object file: No such file or directory

/layers/google.dotnet.runtime/runtime/shared/Microsoft.NETCore.App/8.0.10/libgdiplus: cannot open shared object file: No such file or directory

/layers/google.dotnet.publish/publish/bin/runtimes/unix/lib/netcoreapp3.0/libgdiplus: cannot open shared object file: No such file or directory

/layers/google.dotnet.publish/publish/bin/runtimes/linux-x64/native/liblibgdiplus: cannot open shared object file: No such file or directory

/layers/google.dotnet.runtime/runtime/shared/Microsoft.NETCore.App/8.0.10/liblibgdiplus: cannot open shared object file: No such file or directory

/layers/google.dotnet.publish/publish/bin/runtimes/unix/lib/netcoreapp3.0/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 —”

Is it possible to run these libraries on GCP Cloud Functions?

We have searched the forums and found that some developers are having to use Aspose.Drawing to resolve the above issue, but we are not sure if the same solution applies to this issue.

Any help would be greatly appreciated.

Thanks,
Navya

@NCheramalla

It seems that you are encountering an issue with loading the libgdiplus library while using the Aspose.Html library for .NET in a Google Cloud Function. This error typically arises when the required native library is not available in the environment where your application is running.

To address this issue, consider the following steps:

  1. Check for libgdiplus Installation: Ensure that libgdiplus is installed in your Google Cloud Function environment. You may need to include it in your deployment package or use a custom Docker image that has libgdiplus pre-installed.

  2. Use Aspose.Drawing: As you mentioned, some developers have found success by using the Aspose.Drawing library instead of relying on System.Drawing.Common. Aspose.Drawing is designed to work in environments where libgdiplus may not be available, and it can help avoid the dependency issues you are facing.

  3. Docker Container: If you are using a Docker container for your Google Cloud Function, you can create a Dockerfile that installs libgdiplus. Here’s a simple example of how you might set this up:

    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
    WORKDIR /app
    COPY . .
    RUN apt-get update && apt-get install -y libgdiplus
    ENTRYPOINT ["dotnet", "YourApp.dll"]
    
  4. Check for Updates: Ensure that you are using the latest version of the Aspose.Html library, as improvements and fixes are continuously being made. The latest versions may have better support for Linux environments and could potentially resolve your issue.

  5. Consult Documentation and Forums: For further assistance, consider checking the Aspose forums and documentation for any specific guidance related to running Aspose libraries in cloud environments.

By following these steps, you should be able to resolve the libgdiplus loading issue and successfully run your application in Google Cloud Functions.

If you need more detailed guidance or examples, feel free to ask!

Sources:
[1]: Libgdiplus issue