NullReferenceException creating PDF in Linux

When rendering PDF in linux, NullReferenceException thrown (see stack trace below). This same render works fine in Windows.

Ubuntu 22.04, relevant packages installed:
dotnet-sdk-6.0
libc6-dev l
ibgdiplus
libx11-dev

	"message": "Object reference not set to an instance of an object.",
	"type": "System.NullReferenceException",
	"stack_trace": "Exception 01 ===================================

Type: System.NullReferenceException
Source: \u000F , Aspose.HTML, Version=22.10.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56
Message: Object reference not set to an instance of an object.
Trace: at \u000F .\u000E \u0002(\u0006 \u0002, Char \u0003)
at \u000F .\u000E \u0002(\u0006 \u0002)
at \u0003 .\u0002(\u0003 \u0002, \u000E \u0003, \u0002 \u0005)
at \u0002 …ctor(\u0003 \u0002, IBrowsingContext \u0003, \u000E \u0005)
at \u0003 …ctor(Node \u0002, \u000E \u0003, \u0003 \u0005)
at \u0003 …ctor(Element \u0002, \u0003 \u0003)
at \u0003 .\u0002(Element \u0002, \u000F \u0003, \u0003 \u0005, \u0003 \b, \u0003 \u0006, \u000E \u000E)
at \u0003 .\u0002(Element \u0002, \u000F \u0003, \u0003 \u0005, \u000E \b)
at \u000E .\u0002(Document \u0002, RenderingOptions \u0003, IDevice \u0005, \u0005 \b, \u0003 \u0006, \u0005 \u000E)
at \u000E .\u0005 \u0002(IDevice \u0002, \u0005 \u0003)
at \u0003 .\u0003()
at \u0003 .\u000E \u0002(Renderer \u0002, \u0005 [] \u0003, IDevice \u0005, TimeSpan \b)
at Aspose.Html.Rendering.HtmlRenderer.\u0002(IDevice \u0002, TimeSpan \u0003, Element[] \u0005, Document[] \b)
at Aspose.Html.Rendering.HtmlRenderer.Render(IDevice device, TimeSpan timeout, Document[] documents)
at Aspose.Html.Rendering.Renderer1.Render(IDevice device, TDocument document, TimeSpan timeout) at Aspose.Html.Rendering.Renderer1.Render(IDevice device, TDocument document)
at \b .\u0002(\u0006 \u0002, IDevice \u0003)
at \b .\u0005 \u0002(\u0006 \u0002, PdfSaveOptions \u0003, ICreateStreamProvider \u0005)
at \b .\u0005 \u0002(HTMLDocument \u0002, PdfSaveOptions \u0003, String \u0005)
at PdfProcessor.CreateZip(Template template) in C:\agent\_work\…\PdfProcessor.cs:line 182
at PdfProcessor.Run(RuntimeConfig config) in C:\agent\_work\…\PdfProcessor.cs:line 74
at Reporting.ProcEm(IConsoleAppHostArgs args, ReportingConfig config) in C:\agent\_work\…\Reporting.cs:line 56
at Reporting.Run(IConsoleAppHostArgs args) in C:\agent\_work\…\Reporting.cs:line 33
Location:
Method: \u000F \u000E \u0002(\u0006 , Char) (0, 0)

@saltworks

Would you please make sure that all Windows font (msttcorefonts package) are properly installed in your system. Also, please make sure that you are using the latest version of the API. In case issue still persists, please share your sample HTML in .zip format along with complete sample code snippet with us. We will further proceed to assist you accordingly.

Hi there,

Added the recommended font package, and as you can see from the output we’re on the latest Aspose.HTML API (22.10). We now have a new error. If there is guidance on how to install dependencies for Aspose.HTML in linux or Ubuntu specifically I’d be happy to work with that documentation.

“message”: “The type initializer for ‘Gdip’ threw an exception.”,
“type”: “System.TypeInitializationException”,
“stack_trace”: "Exception 01 ===================================
Type: System.TypeInitializationException
Source: System.Drawing.SafeNativeMethods+Gdip, System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Message: The type initializer for ‘Gdip’ threw an exception.
Trace: at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix2(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy, IntPtr& matrix)
at System.Drawing.Drawing2D.Matrix…ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy)
at Aspose.Html.Rendering.Pdf.PdfDevice.BeginPage(SizeF size)
at \u0002 .\u000F \u0002(IDevice \u0002)
at \u0003 .\u000E \u0002(Renderer \u0002, \u0005 [] \u0003, IDevice \u0005, TimeSpan \b)
at Aspose.Html.Rendering.HtmlRenderer.\u0002(IDevice \u0002, TimeSpan \u0003, Element[] \u0005, Document[] \b)
at Aspose.Html.Rendering.HtmlRenderer.Render(IDevice device, TimeSpan timeout, Document[] documents)
at Aspose.Html.Rendering.Renderer1.Render(IDevice device, TDocument document, TimeSpan timeout) at Aspose.Html.Rendering.Renderer1.Render(IDevice device, TDocument document)
at \b .\u0002(\u0006 \u0002, IDevice \u0003)
at \b .\u0005 \u0002(\u0006 \u0002, PdfSaveOptions \u0003, ICreateStreamProvider \u0005)
at \b .\u0005 \u0002(HTMLDocument \u0002, PdfSaveOptions \u0003, String \u0005)
at PdfProcessor.CreateZip(Template template) in C:\agent\_work\…\PdfProcessor.cs:line 182
at PdfProcessor.Run(RuntimeConfig config) in C:\agent\_work\…\PdfProcessor.cs:line 74
at Reporting.ProcEm(IConsoleAppHostArgs args, ReportingConfig config) in C:\agent\_work\…\Reporting.cs:line 56
at Reporting.Run(IConsoleAppHostArgs args) in C:\agent\_work\…\Reporting.cs:line 33
Location:
Method: Int32 GdipCreateMatrix2(Single, Single, Single, Single, Single, Single, IntPtr ByRef) (0, 0)
\tException 02 inner --------------------------
\tType: System.DllNotFoundException
\tSource: System.Drawing.SafeNativeMethods+Gdip, System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
\tMessage: 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
\tTrace: at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip…cctor()
\tLocation:
\tMethod: Int32 GdiplusStartup(IntPtr ByRef, StartupInput ByRef, StartupOutput ByRef) (0, 0)

@saltworks

Such errors/exceptions occur either when fonts are missing or libgdiplus package is outdated. However, your concerns have been recorded and we have logged a task (HTMLNET-4109) to create complete user guide on how to use Aspose.HTML in Linux like operating systems. We will keep you posted with the status of the ticket in this forum thread. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thanks for the future documentation. The packages I have installed for libgdiplus include the following:

libc6-dev/jammy-updates,now 2.35-0ubuntu3.1 amd64
libgdiplus/jammy 6.0.4+dfsg-2 amd64
libx11-dev/jammy 2:1.7.5-1 amd64
Index of /ubuntu jammy/multiverse amd64 ttf-mscorefonts-installer all 3.8ubuntu2

While we wait for the documentation, these are showing as the latest versions (I installed them with apt install this week). Do I have the right versions? Any packages I’m missing (Ubuntu 22.04)?

Thanks!

@saltworks

The installations and versions seem fine. We are currently investigating the cause behind this issue that you are facing and investigation is being carried out under the logged ticket ID. We will soon update you once the investigation is done and we have some feedback to share with you. Please spare us some time.

We are sorry for the inconvenience.