Hi,
We are migrating .Net 6 to .Net 8 and facing the below issue with Aspose.Html on linux. Even using Aspose.Drawing but facing the below error -
13:46:34 Error Message:
13:46:34 System.TypeInitializationException : The type initializer for ‘Gdip’ threw an exception.
13:46:34 ---- System.PlatformNotSupportedException : System.Drawing.Common is not supported on non-Windows platforms. See Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn for more information.
13:46:34 Stack Trace:
13:46:34 at System.Drawing.SafeNativeMethods.Gdip.GdipCreatePath(Int32 brushMode, IntPtr& path)
13:46:34 at System.Drawing.Drawing2D.GraphicsPath…ctor(FillMode fillMode)
13:46:34 at System.Drawing.Drawing2D.GraphicsPath…ctor()
13:46:34 at …ctor()
13:46:34 at …ctor(ImageRenderingOptions , ICreateStreamProvider )
13:46:34 at . (ImageRenderingOptions , ICreateStreamProvider )
13:46:34 at Aspose.Html.Rendering.Image.ImageDevice…ctor(ImageRenderingOptions options, ICreateStreamProvider streamProvider)
13:46:34 at . ( , ImageSaveOptions , ICreateStreamProvider )
13:46:34 at Aspose.Html.Converters.Converter.ConvertHTML(HTMLDocument document, ImageSaveOptions options, ICreateStreamProvider provider)
Please can you help with above.
@SoniaYadav101
We are looking into it and will be sharing our feedback with you shortly.
@SoniaYadav101
Can you please try installing libgdiplus package as well as msttcorefonts? In case issue still persists, please share complete code sample along with sample file(s) so that we can further investigate accordingly. Please also make sure to use the latest version before sharing the requested information.
@asad.ali
Yes, I am installing below packages with dotnet/sdk:8.0.403-bookworm-slim. Docker file -
USER root **
# Install GDI+ lib needed for Aspose.Cells
RUN apt-get update *
** && apt-get install -y --allow-unauthenticated *
** libc6-dev *
** libgdiplus *
** libx11-dev **
** && rm -rf /var/lib/apt/lists/***
** ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false**
# Ensure that MS fonts are available, needed for PDF generation with Aspose.
RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
RUN fc-cache -f -v
I am calling the method - ConvertHTML(HTMLDocument document, ImageSaveOptions options, ICreateStreamProvider provider) and it’s using system.drawaing.drawing2D for rendering the image and .Net 8 removed the System.Drawaing.Common which impacted system.drawaing.drawing2D too.
For reference -
image.png (52.4 KB)
Below is the code base-
try
{
var saveOptions = new ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Bmp);
saveOptions.BackgroundColor = (System.Drawing.Color)(options.BackgroundColor ==null? System.Drawing.Color.White: options.BackgroundColor);
saveOptions.PageSetup.AdjustToWidestPage = true;
saveOptions.PageSetup.AnyPage.Size.Height = Unit.FromInches(options.MaxHeightInInches);
saveOptions.PageSetup.AnyPage.Margin.Right = Unit.FromPixels(options.AdditionalRightMarginInPixels);
saveOptions.HorizontalResolution = Unit.FromDotsPerInch(options.DotsPerInch);
saveOptions.VerticalResolution = Unit.FromDotsPerInch(options.DotsPerInch);
Converter.ConvertHTML(document, saveOptions, new ExistingStreamAdapter(destination));
}
Bolded line ConvertHTML is throwing exceptions while rendering the Image from html to bmp
@SoniaYadav101
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): HTMLNET-5895
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thank you @asad.ali
I hope it will be fixed soon.
My project has the same problem. This is the only library that does not have proper Linux support from the Aspose products we use yet.
Please remove the System.Drawing.Common dependency or create a .CrossPlatform (as with Aspose.Slides) or a .Drawing (as with Aspose.Pdf) package. This has been an issue for some time now, and I had hoped that you removed System.Drawing.Common dependency as per 2024.10.0 release notes.
@simensnc
We have updated the ticket information and have logged your comments under it as well. We will surely consider them and inform you as soon as the ticket is resolved. Please be patient and spare us some time. We are sorry for the inconvenience.
@simensnc
@SoniaYadav101
In the last release, we removed usage of the System.Drawing.Common from the public methods in order to facilitate the transition between usage of the System.Drawing.Common
and others Drawing libraries.
@asad.ali
We are using the version - 24.10.0 and system.drawing.drawing2D is part of system.drawing.common as it’s clear with exception message.
Please can you confirm which version you have fixed it for .Net8?
I am able to see below fixes but not able to see the fix converting html to image(bmp etc.) which internally using the system.drawing.drawing2D while converting html to image.
image.png (37.9 KB)
Please help me if I am missing any information.
@SoniaYadav101
It was supposed to mean that we have started the transition to remove the System.Drawing.Common dependencies. The work is started by removing it from public methods now and we will continue replacing it internally as well with some alternate component. As soon as the ticket is resolved, we will inform you via this forum thread. Please spare us some time.
@SoniaYadav101
We have released Aspose.HTML.Drawing for .NET which is not dependent on System.Drawing. It can be downloaded here NuGet Gallery | Aspose.HTML.Drawing 24.11.0.
The issues you have found earlier (filed as HTMLNET-5895) have been fixed in this update. This message was posted using Bugs notification tool by avpavlysh