I recently ran into a issue with Aspose.PDF where it fails when converting PDF to Image. It was giving a System.OutOfMemoryException and in error logs i found that the error comes from the
System.Drawing.Common which uses the libgdiplus as the main provider of the cross-platform implementation of
System.Drawing.Common on the native side. When we deploy the same code to Azure App service Environment(Windows) this error never occurred and error appears only for Linux.
some of the error logs as below:
** (process:24425): WARNING **: Path conversion requested 8582688 bytes (1224 x 1753). Maximum size is 8388608 bytes.
System.OutOfMemoryException: at System.Drawing.SafeNativeMethods+Gdip.CheckStatus (System.Drawing.Common, Version=188.8.131.52, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.Drawing.Graphics.get_ClipBounds (System.Drawing.Common, Version=184.108.40.206, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at #=zPJj50tEShreZcXmmZPJN5_dN8VOB10cgOQW$e0o=.#=zB3VnxjIIPIEv (Aspose.PDF, Version=220.127.116.11, Culture=neutral, PublicKeyToken=716fcc553a201e56)
I already installed libgdiplus using apt-get in aspnetcore 5.0 image but after closer look at the version installed I found that the Debian is still on version 4.2 of libgdiplus which is very old.
below is the output from dpkg -l libgdiplus
After couple of unsuccessful attempt to install the latest using mono download link and following there installation guide which retrieve deb from the
"deb https://download.mono-project.com/repo/debian stable-buster main" (which is still on version 4.2) I found a solution which mentioned here in mono docs.
Now my libgdiplus installation step in docker file looks like below which is successfully running on aspnetcore 5 container.
ENV MONO_VERSION 18.104.22.168 RUN echo "deb https://download.mono-project.com/repo/debian stable-buster/snapshots/$MONO_VERSION main" > /etc/apt/sources.list.d/mono-official-stable.list \ && apt-get update \ && apt-get install -y mono-runtime \ && rm -rf /var/lib/apt/lists/* /tmp/*
With that one I would be able to get the newer version of libgdiplus as below and It has resolved the System.OutOfMemoryException comes from
You can find the complete docker file in this Github repo.