Getting exception when converting HTML

Hi there,

We are using Aspose.HTML 20.3.0 to convert the attached html1.zip (297 Bytes) to PDF using the following code:

        HTMLDocument htmlDocument = new HTMLDocument(@"html1.html");
        
        var options = new Aspose.Html.Saving.PdfSaveOptions()
        {
            JpegQuality = 100
        };

        Aspose.Html.Converters.Converter.ConvertHTML(htmlDocument, options, @"html1.html.pdf");

We are getting the exception

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at ╚?? ?? ╗(═    ╗, ═ ? ╚)
   at    .╗   ? ╗(String ╗, ═    ╚, Boolean ║)
   at    .╗(ICSSStyleDeclaration ╗, ║ ╚, ╗    ║)
   at    .   ╗, ICSSRule ╚, ICSSStyleDeclaration ║, ╗   , ICSSRuleList ═)
   at    .   ? ╗(String ╗)
   at ═ ?.╗(String ╗, Element ╚)
   at Aspose.Html.HTMLElement.get_Style()
   at ═ ?.╗(?? ╗, Element ╚, String ║)
   at ║??.??? ╗(Int32 ╗)
   at ??.╚(Int32 ╗)
   at ═ ?.╗(Element ╗, String ╚, Int32 ║)
   at ╚   .╗(Node ╗, Node ╚)
   at ╚   .╗(Document ╗)
   at ╚   .   ? ╗(Document ╗, RenderingOptions ╚)
   at       ? ╗(IDevice ╗,    ╚)
   at   .╗()
   at   .MoveNext()
   at ╚   .   ? ╗(Renderer ╗,   [] ╚, IDevice ║, TimeSpan)
   at Aspose.Html.Rendering.HtmlRenderer.Render(IDevice device, TimeSpan timeout, Document[] documents)
   at Aspose.Html.Rendering.Renderer`1.Render(IDevice device, TDocument document, TimeSpan timeout)
   at Aspose.Html.Rendering.Renderer`1.Render(IDevice device, TDocument document)
   at  ?.╗( ? ╗, IDevice ╚)
   at  ?.═ ?? ╗( ? ╗, PdfSaveOptions ╚, ICreateStreamProvider ║)
   at  ?.═ ?? ╗(HTMLDocument ╗, PdfSaveOptions ╚, String ║)
   at Aspose.Html.Converters.Converter.ConvertHTML(HTMLDocument document, PdfSaveOptions options, String outputPath)

mainly because the html inside is not well-formed.

Is there any way we could fix it prior to converting it? Or tweaking some PdfSaveOptions? Or any kind of workaround that would just not break the conversion process?

Taking a note here that we get the same exception if we use the following code to convert to PDF:

        input.Position = 0;

        var htmlLoadOptions = new HtmlLoadOptions(conversionOptions.ResourcesBasePath)
        {
            InputEncoding = "utf-8"
        };
        
        if (conversionOptions.Margins != null)
        {
            htmlLoadOptions.PageInfo =
                new PageInfo
                {
                    Margin = new MarginInfo
                    {
                        Left = conversionOptions.Margins.Left,
                        Right = conversionOptions.Margins.Right,
                        Top = conversionOptions.Margins.Top,
                        Bottom = conversionOptions.Margins.Bottom
                    }
                };
        }

        var document = new Document(input, htmlLoadOptions);

Thank you!

@gwert,

We have logged an investigation ticket as HTMLNET-2559 in our issue tracking system. We will further investigate the scenario in details and keep you posted with the status of ticket resolution. Please spare us little time.

We are sorry for the inconvenience.

Hi. Any update on this issue?
What’s interesting is that I’m getting the same exception when I run my .Net Core app inside docker, but it’s totally fine on the host system…
Aspose.Html 20.5.0

@Evil_Satanson

Regretfully, the ticket is not yet resolved. Please note that it is logged under free support model and will be resolved on first come first serve basis. We will surely inform you within this forum thread as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Ok, no worries. But are there any insights why would it crash in Docker env and work perfectly in the host Linux system? Any specific system resources that Html2Pdf converter requires?

System.NullReferenceException: Object reference not set to an instance of an object.
   at    .       (   , Char )
   at    .       (   )
   at   .    ,    ,     )
   at    ..ctor    , IBrowsingContext ,    )
   at   ..ctor(Node ,    ,    )
   at    .(Element ,     ,     ,    ,    ,     )
   at    .(Element ,     ,     ,    )
   at    .(Document , RenderingOptions , IDevice ,    )
   at    .       (IDevice ,     )
   at   .()
   at   .MoveNext()
   at    .       (Renderer ,    [] , IDevice , TimeSpan)
   at Aspose.Html.Rendering.HtmlRenderer.Render(IDevice device, TimeSpan timeout, Document[] documents)
   at Aspose.Html.Rendering.Renderer`1.Render(IDevice device, TDocument document, TimeSpan timeout)
   at Aspose.Html.Rendering.Renderer`1.Render(IDevice device, TDocument document)
   at   .(   , IDevice )
   at   .      (   , PdfSaveOptions , ICreateStreamProvider )
   at Aspose.Html.Converters.Converter.ConvertHTML(HTMLDocument document, PdfSaveOptions options, ICreateStreamProvider provider)
   at SmartRender.Html2Pdf.BuildDoc(String data)

@Evil_Satanson, @gwert

We would like to share with you that earlier logged ticket has been resolved and cannot be reproduced using Aspose.HTML for .NET 20.5. Would you please try using latest version of the API.

Would you please test with latest version and in case the issue still occurs, please share your sample code snippet with us along with source HTML. We will further proceed to assist you accordingly.