System.NullRefernceException: object reference not set to an instance of an object

Hello.
I get the same message “Object reference not set to an instance of an object” on this line:

return new Document(new MemoryStream(pdfBytes), loadOptions);

This happens on Linux, but not on Windows:

We are using Aspose.PDF.Drawing v. 23.7.0

Hole log:
Error Message:
2023-09-05T11:29:42.1656019Z Test method DokumentKonvertering.Tests.Transform.AsposeHelperTests.CreateFromHtml_OK threw exception:
2023-09-05T11:29:42.1657921Z System.NullReferenceException: Object reference not set to an instance of an object.
2023-09-05T11:29:42.1659537Z Stack Trace:
2023-09-05T11:29:42.1659982Z at #=znlEvUxzsdZ95jGjqpBUJB7AJgHBG4HngTK1BTrA=.#=zsuXy3av9$OD_(#=z6jWF9ElryXArxxSr9cVW8PPSdAkXmCt1Xw== #=z0p1XIqo=, Char #=zSNJFsUo=)
2023-09-05T11:29:42.1660696Z at #=znlEvUxzsdZ95jGjqpBUJB7AJgHBG4HngTK1BTrA=.#=zsuXy3av9$OD_(#=z6jWF9ElryXArxxSr9cVW8PPSdAkXmCt1Xw== #=z0p1XIqo=)
2023-09-05T11:29:42.1661337Z at #=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA==.#=zre1H1oBNVGH0(#=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA== #=zdvZi9ks=, #=zYKcOg2Q3xi3JuIxBvlRnusI442UyyxGIrCuZ1n4= #=zUKLw3S0=, #=zrJ1k69oIrv8xJMmMblu1uyOFP0Rb1Smjkg== #=zr2drt8I=)
2023-09-05T11:29:42.1662151Z at #=zQ7Q8eeBLfKm4pIi$snx961KOkfzMQXp4_Zq8kis=…ctor(#=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA== #=zdvZi9ks=, #=zkizDnWC8chiJoEpohi2EhkcPFxD4 #=zncHgIAs=, #=zYKcOg2Q3xi3JuIxBvlRnusI442UyyxGIrCuZ1n4= #=zUKLw3S0=)
2023-09-05T11:29:42.1662896Z at #=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA==…ctor(#=zk1qssx3d51bPEvHniBteQlk= #=zvZkFd3U=, #=zYKcOg2Q3xi3JuIxBvlRnusI442UyyxGIrCuZ1n4= #=zUKLw3S0=, #=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA== #=zweYtH4rSK2XN)
2023-09-05T11:29:42.1663552Z at #=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA==…ctor(#=z0qSfyA1HudPpsglbtvviMws= #=zWCWRNaM=, #=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA== #=zweYtH4rSK2XN)
2023-09-05T11:29:42.1664471Z at #=z9LDR0$ahXcOp90XLBBrrJPf4BHv1qeCz2w==.#=zWlHr2KB38CPQ(#=z0qSfyA1HudPpsglbtvviMws= #=zWCWRNaM=, #=zDw4pDqY6K1HxxsBhgcbJpD0HGbXyUvR7hQ== #=zpo5ORUM=, #=zllZG4IaWmX8jDBPIOa_ENC_LNEA_ar9QUw== #=z0Gi4OzCAFe2M, #=zG2AGZnB97DoMQUgFWkzwZFXW5RVe #=zJcZkiKg=, #=zTcmheW2kLJ2bX9JhY0tS17mA2VmqH5PyBA== #=zweYtH4rSK2XN, #=zxqFBNF8Zl3cZbqsJQuNp1HHW2U7wkY9vXg== #=zsUpkXuDbLNppcfaByQ==)
2023-09-05T11:29:42.1666062Z at #=z9LDR0$ahXcOp90XLBBrrJPf4BHv1qeCz2w==.#=zjURZAow=(#=z0qSfyA1HudPpsglbtvviMws= #=zWCWRNaM=, #=zDw4pDqY6K1HxxsBhgcbJpD0HGbXyUvR7hQ== #=zpo5ORUM=, #=zllZG4IaWmX8jDBPIOa_ENC_LNEA_ar9QUw== #=z0Gi4OzCAFe2M, #=zxqFBNF8Zl3cZbqsJQuNp1HHW2U7wkY9vXg== #=zsUpkXuDbLNppcfaByQ==)
2023-09-05T11:29:42.1667522Z at #=zlL0yPOonjmQQdnjseL07YTzm_Ycpkynz4g==.#=zJwjHxwhbGmBS(#=zcYOwa2DKi9ikHI_NV$QWHg4= #=zCo7XP8s=, #=zuSsyhxhe9NzYlSO7nclNsZNU0czS #=zESWtFUXBW1uAIkHqRA==, #=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=, #=zSZGgSqZ8UC4pNFIXRTAFarf_nfsH #=zD8GhBsQ=, #=zmBwpalQNVdcyUlkmFZR62eSKYppX0rpaShkxj14= #=zaIGgVrG113l$4H_NtKZWX3U=, #=zZtqAzil4x3cIZnhZ85t6Gdk= #=z$iTiqzNMbIzIs40H2g==)
2023-09-05T11:29:42.1668408Z at #=zlL0yPOonjmQQdnjseL07YTzm_Ycpkynz4g==.#=ztOfq64Q=(#=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=, #=zSZGgSqZ8UC4pNFIXRTAFarf_nfsH #=zD8GhBsQ=)
2023-09-05T11:29:42.1668914Z at #=zSZGgSqZ8UC4pNFIXRTAFarf_nfsH.#=ztOfq64Q=(#=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=)
2023-09-05T11:29:42.1669463Z at #=zUNANKYRYiXODrT_f5p8vGpncCgx2yzFIvA==.#=zWpvm6Gg=()
2023-09-05T11:29:42.1669808Z at #=zUNANKYRYiXODrT_f5p8vGpncCgx2yzFIvA==.#=zbOf9gt8=()
2023-09-05T11:29:42.1670389Z at #=zlGzMeNNjDufUGzltlBhQp4wvnyboVvf6PQ==.#=z1E$Sg29TOfML(#=zx95q$KeCPqy3pzg_7HIbbAg= #=z_7$Fuvs_Rf_cyY1H9Q==, #=zSZGgSqZ8UC4pNFIXRTAFarf_nfsH[] #=z8237WSzzBfv_, #=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=, CancellationToken #=zS5D6$$M=)
2023-09-05T11:29:42.1671464Z at #=zCuETAWWVHwf8kYlsKKx7zulCAckO.Render(#=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=, CancellationToken #=zS5D6$$M=, #=z0qSfyA1HudPpsglbtvviMws=[] #=zafyyJQ4=, #=zcYOwa2DKi9ikHI_NV$QWHg4=[] #=zxF16xzw=)
2023-09-05T11:29:42.1672095Z at #=zCuETAWWVHwf8kYlsKKx7zulCAckO.Render(#=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=, TimeSpan #=zrLkaIsY=, #=zcYOwa2DKi9ikHI_NV$QWHg4=[] #=zxF16xzw=)
2023-09-05T11:29:42.1672801Z at #=zphza2laDM5FdyuXJutMfPyYvQwV1.Render(#=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=, #=z_paH9b0= #=zCo7XP8s=, TimeSpan #=zrLkaIsY=)
2023-09-05T11:29:42.1673289Z at #=zphza2laDM5FdyuXJutMfPyYvQwV1.Render(#=z760mL$tXf1wE7e6SrZbXFRHR_iZe #=zFMMqLmI=, #=z_paH9b0= #=zCo7XP8s=)
2023-09-05T11:29:42.1673796Z at #=zCQRcefdqjS9xXXQX$B1Z3VWaaACx.#=z$GVWHqGhxkKD(Stream #=zF5D1cMJTvHml, Document #=zCoyL0DfYnSmT, HtmlLoadOptions #=zTJaKW5uAQ9uj, String #=z9T1K$Zi08Uom)
2023-09-05T11:29:42.1674362Z at #=zCQRcefdqjS9xXXQX$B1Z3VWaaACx.#=z3Q7zvR0=(Stream #=zF5D1cMJTvHml, Document #=zCoyL0DfYnSmT, HtmlLoadOptions #=zTJaKW5uAQ9uj, String #=z9T1K$Zi08Uom)
2023-09-05T11:29:42.1674893Z at #=zCQRcefdqjS9xXXQX$B1Z3VWaaACx.#=z3Q7zvR0=(Stream #=zF5D1cMJTvHml, Document #=zCoyL0DfYnSmT, HtmlLoadOptions #=zTJaKW5uAQ9uj)
2023-09-05T11:29:42.1675317Z at Aspose.Pdf.Document.#=ziu3IFPM=(Stream #=zh$Ez3JE=, LoadOptions #=zLOZHe1U=)
2023-09-05T11:29:42.1675688Z at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
2023-09-05T11:29:42.1676281Z at DokumentKonvertering.Logic.Utilities.AsposePdfHelper.CreateDocument(Byte[] pdfBytes, LoadOptions loadOptions) in /agent/_work/18/s/Source/DokumentKonvertering/DokumentKonvertering.Logic/Utilities/AsposePdfHelper.cs:line 37
2023-09-05T11:29:42.1676996Z at DokumentKonvertering.Logic.Utilities.AsposePdfHelper.CreateFromHtml(Byte[] html) in /agent/_work/18/s/Source/DokumentKonvertering/DokumentKonvertering.Logic/Utilities/AsposePdfHelper.cs:line 99
2023-09-05T11:29:42.1677690Z at DokumentKonvertering.Tests.Transform.AsposeHelperTests.CreateFromHtml_OK() in /agent/_work/18/s/Source/DokumentKonvertering/DokumentKonvertering.Tests/Transform/AsposeHelperTests.cs:line 45

This was solved for me upgrading to Aspose.PDF.Drawing v.23.8.0

@koo1540

Its nice to know that your issue has been resolved. Please keep using the API and feel free to create a new topic in case you face any issues.

This seems to not be the exactly truth. You also seem to need the libgdiplus package installed on the Linux server. Are you aware of this and will you be removing this dependency in the (near) future?

@koo1540

Yes, we are aware of this dependency. libgdiplus and msttcorefonts packages need to be installed in non-Windows or Linux like environment in order to get the API working correctly. An investigation ticket as PDFNET-55450 has been logged in our issue tracking system to analyze removal of libgdiplus dependency. We will inform you as soon as the ticket is resolved. Please spare us some time.

Hi.

What’s the status regarding removal of dependency on libgdiplus in Linux environments?

@koo1540

We have published a beta API i.e. Aspose.Pdf.Drawing which does not include the dependency on System.Drawing and we launched it specifically to work in both Windows and Linux like platforms. Furthermore, there is no need to install the libgdiplus library - in .Net 7 it is not supported. You can try to use Aspose.Pdf.Drawing in the Linux platform to see if it is working correctly. Once we are sure that everything is fine, we will make it permanent part of existing Aspose.PDF for .NET API. Until then, you won’t need any separate license or code change to use this API. It has all classes same as existing Aspose.PDF for .NET.

Long time. No see. :wink:

Above you wrote: “…Once we are sure that everything is fine, we will make it permanent part of existing Aspose.PDF”. To mee it seems that still it’s only Aspose.Pdf.Drawing that is working in a Linux environment. Here: https://docs.aspose.com/pdf/net/drawing/

And the requirement to install libgdiplus/mscorefonts(contradiction to you answer above) are back:

@koo1540

Sadly, we had to shift the deadlines since not all known issues have been resolved in Aspose.Drawing . Our primary goal is to prevent any performance degradation. While we know that System.Drawing is still faster in some cases, we don’t want to deprive customers of an alternative.

Once we are confident that the Aspose.Drawing-based version performs as well as or better than the original System.Drawing-based version in all cases, we will proceed with merging them. We are actively working with the team to achieve this as soon as possible.

As far as you need Linux support, you should continue using the Aspose.PDF.Drawing version.

Hva about libgdiplus/mscorefonts? Why are they now needed in containers on Linux?

@koo1540

About msttcorefonts package, it is needed regardless of the API variant you are using because Aspose.PDF relies on system fonts in order to process PDF documents. If MS Fonts are not present in the system, the API may produce unexpected results and behave unexpectedly.

About libgdiplus package, it is basically required if you are using Aspose.PDF for .NET instead of Aspose.Pdf.Drawing. Also, please note that Aspose.Pdf.Drawing is not fully independent of System.Drawing.Common. It uses this dependency for specific functionality like printing.

Interesting to know why the error starting this conversation is back?! It was gone at one point in time after you wrote:

"We have published a beta API i.e. Aspose.Pdf.Drawing which does not include the dependency on System.Drawing and we launched it specifically to work in both Windows and Linux like platforms. Furthermore, there is no need to install the libgdiplus library " .

Have installed:
Aspose.PDF.Drawing Version=“25.2.0” &
Aspose.Words Version=“25.2.0”

and it fails on Linux (not Windows).


System.NullReferenceException: Object reference not set to an instance of an object.
Stack Trace:
at #=zDQJyf6D55_JAP7L1I$EZk5dFMmQ7jnn4vtUwncI=.#=zDjOpUXVOej7s(#=zDptoe4B18qLu0BvjqWocX1j4tAxufYG9Tw== #=zQYScpjI=, Char #=zv3vXU90=)
at #=zDQJyf6D55_JAP7L1I$EZk5dFMmQ7jnn4vtUwncI=.#=zDjOpUXVOej7s(#=zDptoe4B18qLu0BvjqWocX1j4tAxufYG9Tw== #=zQYScpjI=)
at #=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w==.#=z936bxIEqnjTg(#=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w== #=zs6WOAs4=, #=zgJTy_UqM9M0zqAxoTqtzG8CtpScQxirvTWmPUGo= #=z1G$jScQ=, #=zX55AdVohcR8X75C4priWE$oEEOhODMJrWA== #=zk5a1D7o=)
at #=zo6QK9VaaZFgXIa9RUd9Htnuorn4TDxJZQ77KV7o=…ctor(#=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w== #=zs6WOAs4=, #=zmlux4gV7zwMQm5xQypWD4T_mR0pp #=zNX063bI=, #=zgJTy_UqM9M0zqAxoTqtzG8CtpScQxirvTWmPUGo= #=z1G$jScQ=)
at #=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w==…ctor(#=zH9Y$t9i03DFu7KAQC0GtcOI= #=z6WWEY2k=, #=zgJTy_UqM9M0zqAxoTqtzG8CtpScQxirvTWmPUGo= #=z1G$jScQ=, #=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w== #=z2SokRW7LMrQl)
at #=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w==…ctor(#=z8djGXc2JnZqp0jDdfUwW7_s= #=zyXUC$RU=, #=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w== #=z2SokRW7LMrQl)
at #=zQREQBUac5joBjfmLjy7U0GHR0YE1h6O9Lw==.#=zpGpJ0hA6lJhu(#=z8djGXc2JnZqp0jDdfUwW7_s= #=zyXUC$RU=, #=z8H9ZmIr4tUlyj0ykPk6_SDwOhQqP8Sgv2g== #=z$FhB0ek=, #=zyjJ6Oq9bD00MXpS_6xTtaiFkjFXJO4Y3aQ== #=z$cDOv_U9YCen, #=zEdQiEogQxMYsHMiU96Zk7hdDq5cM #=zmeTP29o=, #=zTsitXhEFjFphokjgssuaKZTVauj0X1GE4w== #=z2SokRW7LMrQl, #=zEdQiEogQxMYsHMiU96Zk7nQzUmDdUWMa4g== #=zMohdo4LwwJxuq3twUw==)
at #=zQREQBUac5joBjfmLjy7U0GHR0YE1h6O9Lw==.#=zPa9mM1M=(#=z8djGXc2JnZqp0jDdfUwW7_s= #=zyXUC$RU=, #=z8H9ZmIr4tUlyj0ykPk6_SDwOhQqP8Sgv2g== #=z$FhB0ek=, #=zyjJ6Oq9bD00MXpS_6xTtaiFkjFXJO4Y3aQ== #=z$cDOv_U9YCen, #=zEdQiEogQxMYsHMiU96Zk7nQzUmDdUWMa4g== #=zMohdo4LwwJxuq3twUw==)
at #=z_jefYa9_eB3c1yJ5eI35AeUVn9Yh1RaNwA==.#=zVGXwf1sqo9Kk(#=zj3_ChkUtKgVRo9ki01jYOpY= #=zH8cB6kE=, #=z6e1Iw9bhCoIDROC$5War8iuwayRQ #=zO76hmkI30qbtZAJVZg==, #=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=, #=zlKBaotCeJ38DwtNTDPhrqzYOjiP7 #=zhW7rJus=, #=z_A$Rq9OVKyWy2NSbptLy1roPuVqnlMtL96EGPao= #=zPg9Mp7GH56pUzxYxohVitk8=, #=zAo7NTOFWlIxEbm93sWkviSY= #=zRUvjlEeHPpKvAtTBTA==)
at #=z_jefYa9_eB3c1yJ5eI35AeUVn9Yh1RaNwA==.#=zwdp8PRs=(#=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=, #=zlKBaotCeJ38DwtNTDPhrqzYOjiP7 #=zhW7rJus=)
at #=zlKBaotCeJ38DwtNTDPhrqzYOjiP7.#=zwdp8PRs=(#=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=)
at #=za1kPf29WbN4LzGc5wJsOgFgwUEln9wK3_w==.#=z1xP$5Ps=()
at #=za1kPf29WbN4LzGc5wJsOgFgwUEln9wK3_w==.#=zMDQFjPY=()
at #=z2MCrFtDNmd3UxaOWZ93Pin_Ajk7L.#=zASk7YLTVMV5p(#=ziubIULQpSaS6rnp1ZU9sE_M= #=zkfw4KQXjXhK0lvpCow==, #=zlKBaotCeJ38DwtNTDPhrqzYOjiP7[] #=zHQOmKGKprx8M, #=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=, CancellationToken #=zg04nzqo=)
at #=zvD_SN3KJ1OgF_CZUobRE_zc7sKdm.Render(#=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=, CancellationToken #=zg04nzqo=, #=z8djGXc2JnZqp0jDdfUwW7_s=[] #=z3UQJ_hw=, #=zj3_ChkUtKgVRo9ki01jYOpY=[] #=zX1zVzLQ=)
at #=zvD_SN3KJ1OgF_CZUobRE_zc7sKdm.Render(#=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=, TimeSpan #=zdoWy9Aw=, #=zoaoNCEtXYO71kToYDceriyE=[] #=zODXQChw=)
at #=zvVBv_wG_6k_9MufHPH1afSzQwbxp.Render(#=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=, #=zyDnne7E= #=zaJYyfT0=, TimeSpan #=zdoWy9Aw=)
at #=zvVBv_wG_6k_9MufHPH1afSzQwbxp.Render(#=zjps6DzM3l0TfjS31QkOgbiY30UPx #=zgHczF2g=, #=zyDnne7E= #=zaJYyfT0=)
at #=ziIQ7tKG3b9eqhLuBsBTh3gBhrCU7.#=zilhnYW2fJpPL(Stream #=zkO0E2lzFy2O8, Document #=zW1biBi5dM8Q9, HtmlLoadOptions #=zMABhzq8fy6se, String #=zNpeJNhvpEkv2)
at #=ziIQ7tKG3b9eqhLuBsBTh3gBhrCU7.#=zOLUIskg=(Stream #=zkO0E2lzFy2O8, Document #=zW1biBi5dM8Q9, HtmlLoadOptions #=zMABhzq8fy6se, String #=zNpeJNhvpEkv2)
at #=ziIQ7tKG3b9eqhLuBsBTh3gBhrCU7.#=zOLUIskg=(Stream #=zkO0E2lzFy2O8, Document #=zW1biBi5dM8Q9, HtmlLoadOptions #=zMABhzq8fy6se)
at Aspose.Pdf.Document.#=zx0hfH7I=(Stream #=zV6LXPx4=, LoadOptions #=zluWKvbE=, Boolean #=z5vqfGd$O26MJ)
at Aspose.Pdf.Document.#=zx0hfH7I=(Stream #=zV6LXPx4=, LoadOptions #=zluWKvbE=)
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
at DokumentKonvertering.Logic.Utilities.AsposePdfHelper.CreateDocument(Byte[] pdfBytes, LoadOptions loadOptions)

@koo1540

Such errors may occur due to missing fonts in the System. Please make sure that all the fonts that are required in the process, are present and properly installed. In case issue still persists, please share your sample document with us along with sample code snippet so that we can test the scenario in our environment and address it accordingly.

Hi, again.

I’ve concluded after testing this now that we don’t need the libgdiplus library when using the Aspose.PDF.Drawing on Linux (this is true for Aspose.PDF as well) at least for our purposes…
But we need to install the mscorefonts. So this is needed for Linux (in our Docker-file):

apt-get update
echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
apt update
apt-get install -y ttf-mscorefonts-installer -y

Question: Are you going to remove this dependency on mscorefonts in future Aspose.Pdf.Drawing pacages? Due to this dependency we are not able to use chisseled image for Linux.

We are afraid that would not be the case because as shared earlier - Aspose.PDF relies on System Fonts to process/modify and convert PDF documents. These fonts should be present in the system (Windows/Linux). In case of non-Windows environment, these fonts need to be installed separately.