Object reference not set to an instance of an object for Aspose.PDF (.Net) #2

When trying to add an image to an existing PDF or when converting HTML to PDF, we encounter an error. Unfortunately, the cause of the error is not clear from the stack trace. Please help us fix it.

Aspose.PDF v22.12.0
net6.0
Docker, Linux (mcr.microsoft.com/dotnet/aspnet:6.0)

Installed packages:

RUN apt-get update && apt-get install -y libgdiplus
RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

System.NullReferenceException: Object reference not set to an instance of an object.
   at #=zwWHU2QQ8TaAFOp_5cHBbu9_mqEpQJwxLk0S5iTc=.#=zt9NUj8GZ17QG(#=z2QCscfp_3nv4gT788P_12gsEERq$utEx_A== #=zazRv40c=, Char #=z1mn9UaM=)
   at #=zs0vEkpQewtv4sTj2QC1YrV853xiT8LIICLZKXGE=.#=zInvaSRfhJ7pC(#=z7Lcr0Wi4iRhF4aljwAnqvNIEZ_rcIvV0Jg== #=z$OZ14K4=)
   at #=zs0vEkpQewtv4sTj2QC1YrV853xiT8LIICLZKXGE=.#=zInvaSRfhJ7pC(#=z7Lcr0Wi4iRhF4aljwAnqvNIEZ_rcIvV0Jg== #=z$OZ14K4=)
   at #=zs0vEkpQewtv4sTj2QC1YrV853xiT8LIICLZKXGE=.#=zInvaSRfhJ7pC(#=z7Lcr0Wi4iRhF4aljwAnqvNIEZ_rcIvV0Jg== #=z$OZ14K4=)
   at #=zs0vEkpQewtv4sTj2QC1YrV853xiT8LIICLZKXGE=.#=zWXKELE5kl84U(#=z7Lcr0Wi4iRhF4aljwAnqvNIEZ_rcIvV0Jg== #=z$OZ14K4=)
   at #=zs0vEkpQewtv4sTj2QC1YrV853xiT8LIICLZKXGE=.#=zWXKELE5kl84U(#=z7Lcr0Wi4iRhF4aljwAnqvNIEZ_rcIvV0Jg== #=z$OZ14K4=)
   at #=zs0vEkpQewtv4sTj2QC1YrV853xiT8LIICLZKXGE=.#=zWXKELE5kl84U(#=z7Lcr0Wi4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o9Sb0p7S7LjZ.#=zix8VOT8=(#=zGNiwrXDL$xPp2OGWKXGE0WPHrL3K #=zJ8tC_$M=)
   at #=zA_ocQQ_kEOzYosP61Fi1DR4XkbzRChO6Qw==.#=zIjDmnNk=()
   at #=zA_ocQQ_kEOzYosP61Fi1DR4XkbzRChO6Qw==.#=zL27Svjc=()
   at #=zil9AVLI6A1$OqebyaRDRLjYa58P9thWRKg==.#=zkr1eeSEpWXE7(#=z_$BSHpd0$N9_EfoMjeUXXLY= #=zlPhDPXfXqyTCDUY8Xg==, #=zIplRQaoe_jFdoICpo9Sb0p7S7LjZ[] #=zPlyjbFopnT3X, #=zGNiwrXDL$xPp2OGWKXGE0WPHrL3K #=zJ8tC_$M=, TimeSpan #=zLKd4B80=)
   at #=z4azyaFaoI2ccxIcoNSzVwa77ER9_.Render(#=zGNiwrXDL$xPp2OGWKXGE0WPHrL3K #=zJ8tC_$M=, TimeSpan #=zLKd4B80=, #=zDBccz_lZk3ys2XMKhEqFdZI=[] #=zXOELz7A=, #=zWslcjMHd9R6Cz341Srf5e1k=[] #=zoXgsRCo=)
   at #=z4azyaFaoI2ccxIcoNSzVwa77ER9_.Render(#=zGNiwrXDL$xPp2OGWKXGE0WPHrL3K #=zJ8tC_$M=, TimeSpan #=zLKd4B80=, #=zWslcjMHd9R6Cz341Srf5e1k=[] #=zoXgsRCo=)
   at #=zfEKhz8NFcGv5kHD_q5DeBFu_TXWA.Render(#=zGNiwrXDL$xPp2OGWKXGE0WPHrL3K #=zJ8tC_$M=, #=zjfRVYI8= #=zQ9ilHsc=, TimeSpan #=zLKd4B80=)
   at #=zfEKhz8NFcGv5kHD_q5DeBFu_TXWA.Render(#=zGNiwrXDL$xPp2OGWKXGE0WPHrL3K #=zJ8tC_$M=, #=zjfRVYI8= #=zQ9ilHsc=)
   at #=zN6OPlHWVQZbk5xMShkuy_9TCNZhI.#=zXHrH0cHUmMKP(Stream #=ze4E8DzF5biA$, Document #=zBLRbMyMOw1cm, HtmlLoadOptions #=zic3EpTMAgyfH, String #=z1mNV_KL1ITRA)
   at #=zN6OPlHWVQZbk5xMShkuy_9TCNZhI.#=z2TA$9cg=(Stream #=ze4E8DzF5biA$, Document #=zBLRbMyMOw1cm, HtmlLoadOptions #=zic3EpTMAgyfH, String #=z1mNV_KL1ITRA)
   at #=zN6OPlHWVQZbk5xMShkuy_9TCNZhI.#=z2TA$9cg=(Stream #=ze4E8DzF5biA$, Document #=zBLRbMyMOw1cm, HtmlLoadOptions #=zic3EpTMAgyfH)
   at Aspose.Pdf.Document.#=zJ$HTlz0=(Stream #=z3Wdp9mg=, LoadOptions #=z48c_1lM=)
   at Aspose.Pdf.Document..ctor(Stream input, LoadOptions options)

@quotebot
This occurs because from .Net 6 System.Drawing.Common is not supported on non-Windows platform (on Linux in particular).
Use the Aspose.Pdf.Drawing library (instead of Aspose.Pdf). This library uses Aspose.Drawing instead of System.Drawing.Common. Its main limitation is that api printing is not supported at the moment.
Also, when using it, there is no need to use the gdiplus package.

To clarify, the Aspose.Pdf library should be removed from the project and Aspose.Pdf.Drawing included to the project instead.

We have enabled the flag that allows the use of System.Drawing.Common on .NET 6.0.
<RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />

Aspose.PDF was functioning for some time with this configuration.

@quotebot
Try working with Aspose.Pdf.Darwing

Does it mean that the error is definitely related to System.Drawing.Common? Because previously, the same version of Aspose.PDF was working on this environment, and then it stopped working.

According to the stacktrace, the error occurs when working with fonts.
Are you following the recommendations How to Install Aspose.PDF for .NET|Aspose.PDF for .NET (Working with .NET Core DLLs in Non-Windows Environment) and are you currently installed by apt-get install -y ttf-mscorefonts- fontconfig installer?