We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

.NET 5.0 - HtmlFragment - System.NullReferenceException


I’m having problem with Aspose.PDF for .NET and .NET 5.0.

I’m trying to inject some simple HTML code into a PDF and keep getting this exception:

An unhandled exception of type 'System.NullReferenceException' occurred in Aspose.PDF.dll: 'Object reference not set to an instance of an object.'
   at #=zWc4hku6hXlQxyFq0PshpnHqhBd7BvGN6QILrIBQ=.#=zs7Pnh6qRjku_(#=zlBQe85eOQMloTQOtSgv4z2SsRmx1i8Y46g== #=zvi9sCso=, Char #=zMomoXC0=)
   at #=zWc4hku6hXlQxyFq0PshpnHqhBd7BvGN6QILrIBQ=.#=zs7Pnh6qRjku_(#=zlBQe85eOQMloTQOtSgv4z2SsRmx1i8Y46g== #=zvi9sCso=)
   at #=zzumlbqSf0rQXYlOazurtB6gJQaNtFFeeUA==.#=zv8Bdqu0yWy1v(#=zzumlbqSf0rQXYlOazurtB6gJQaNtFFeeUA== #=zqR5_Drk=, #=zZRqBHxu1tUgAXTp3gsbHATDrnIUV0RZk_M6oJC0= #=zccL4if4=, #=zcanpmfJ2gTPh169yulntJXNUIIjI1hj4FQ== #=zn0iL9Hg=) 

This is code I’m using:

Document document = new Document();
Page page = document.Pages.Add();
HtmlFragment htmlFrag = new Aspose.Pdf.HtmlFragment("<div>Hello</>");
Stream outputStream = new MemoryStream();

These are the packages installed in my project:
System.Drawing.Common 5.0.2"
Aspose.PDF 21.7.0

What am I doing wrong?

If I remove the HtmlFragment from the code everything works fine.


I forgot to mention that I’m currently using a Mac and Visual Studio Code, both latest version.


these two issues seem to be identical to mine:


Would you please make sure that all MS True Type fonts are installed in the system where you are facing issue? Also, please make sure to install libgdiplus package as well. In case you still notice any issue with 21.7 version of the API, please let us know.

yes all installed.

I tried pretty much everything mentioned in other two issues as well, but still no luck.


We were able to reproduce the same exception at our end while testing the case in MacOS. Therefore, an issue as PDFNET-50246 has been logged in our issue tracking system for the sake of correction. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.