OutOfMemoryException System.Drawing.Graphics.Save .NET6 System.Drawing.EnableUnixSupport Docker
I have an error when generating report in ASP.NET Core MVC application in .NET6 on docker Linux platform.
I added "System.Drawing.EnableUnixSupport": true in runtimeconfig.template.json file.
The error is
System.OutOfMemoryException: Out of memory. at System.Drawing.Graphics.Save() at FastReport.GdiGraphics.Save() at FastReport.TextObject.CalcSize() at FastReport.TextObject.CalcHeight() at FastReport.BandBase.CalcHeight() at FastReport.Engine.ReportEngine.PrepareBand(BandBase band, Boolean getData) at FastReport.Engine.ReportEngine.ShowBandToPreparedPages(BandBase band, Boolean getData) at FastReport.Engine.ReportEngine.ShowBand(BandBase band, Boolean getData) at FastReport.Engine.ReportEngine.ShowBand(BandBase band) at FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand, Int32 rowCount, Boolean keepFirstRow, Boolean keepLastRow) at FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand) at FastReport.Engine.ReportEngine.RunBands(BandCollection bands) at FastReport.Engine.ReportEngine.RunReportPage(ReportPage page) at FastReport.Engine.ReportEngine.RunReportPages() at FastReport.Engine.ReportEngine.RunReportPages(ReportPage page) at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page) at FastReport.Report.Prepare(Boolean append) at FastReport.Web.Controllers.ReportController.<.ctor>b__0_0()
Hello!
Try to build libgdiplus manually This should fix the problem example:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
RUN
EXPOSE 80
EXPOSE 443
RUN apt update
RUN apt install -y libgif-dev autoconf libtool automake build-essential gettext libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev libpango1.0-dev git
RUN git clone https://github.com/mono/libgdiplus.git
WORKDIR ./libgdiplus
RUN ./autogen.sh --with-pango --prefix=/usr
RUN make
RUN make install
Best regards Marat
Yes, I can confirm, that the problem is with old version of libgdiplus library. I use docker image with .Net 6 and Debian 12 distribution, this version has installed libgdiplus 6.0.4. I updated manually version to 6.12.0. This is my implementation of dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim AS base
RUN apt-get update && apt-get remove libgdiplus -y && apt autoremove -y && apt-get install -y apt-transport-https dirmngr gnupg ca-certificates
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
RUN echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list
RUN apt-get update && apt-get install -y mono-devel
I use the following command to pull, the build is successful, but I see the version is still 6.0.4, is there a problem with my operation?
RUN git clone https://github.com/mono/libgdiplus.git && cd libgdiplus && git checkout release/6.1