System.ArgumentOutOfRangeException while ConvertHTML

Hi Aspose-Support,

I´m trying to convert a html page to pdf and get a System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values. '.

See the code below. The exception occures at Converter.ConvertHTML.

var cc = new CookieContainer();
                foreach (var cookieKey in Request.Cookies.Keys)
                {
                    try
                    {
                        cc.Add(
                            new Uri($"{Request.Scheme}://{Request.Host}{Request.PathBase}"),
                            new Cookie(cookieKey, Request.Cookies[cookieKey]));
                    }
                    catch (CookieException ex)
                    {
                        _logger.LogWarning(ex, $"[{nameof(Print)}] Error while adding cookie to collection");
                    }
                }

 using var request =
                    new RequestMessage(Url.Action("Summary", "Application", new { id = viewModel.ApplicationId }, Request.Scheme))
                    {
                        CookieContainer = cc
                    };

                using var document = new HTMLDocument(request, new Configuration());

                Converter.ConvertHTML(
                    document,
                    new PdfSaveOptions(),
                    Path.Combine(_configuration.AppDataPath, WellKnownDataFolders.Temp, fileName));

See the callstack below, that I get.

   at    ..MoveNext()
   at    . .MoveNext()
   at    . .MoveNext()
   at    . .MoveNext()
   at    . [TSource](IEnumerable`1 , Func`2 , Action )
   at    .(    ,     ,     ,     ,     , Boolean , List`1 , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    ..(Tuple`2 )
   at    . [TSource](IEnumerable`1 , Func`2 , Action )
   at    .(    ,     ,     ,     ,     , Boolean , List`1 , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    , ​   ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    ..(Tuple`2 )
   at    . [TSource](IEnumerable`1 , Func`2 , Action )
   at    .(    ,     ,     ,     ,     , Boolean , List`1 , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    ..(Tuple`2 )
   at    . [TSource](IEnumerable`1 , Func`2 , Action )
   at    .(    ,     ,     ,     ,     , Boolean , List`1 , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    ..(Tuple`2 )
   at    . [TSource](IEnumerable`1 , Func`2 , Action )
   at    .(    ,     ,     ,     ,     , Boolean , List`1 , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    ..(Tuple`2 )
   at    . [TSource](IEnumerable`1 , Func`2 , Action )
   at    .(    ,     ,     ,     ,     , Boolean , List`1 , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(    ,     ,     ,     ,     ,     , Boolean , List`1  , List`1  , List`1  , List`1  )
   at    .(Document ,     ,     ,  ​  , Boolean ,     , Int32 ,      , RenderingOptions  )
   at    .(Document , Int32 ,     ,     , RenderingOptions )
   at    . .MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at    .[TSource](IEnumerable`1 )
   at    .(Document ,     ,     ,     , RenderingOptions )
   at    .(Document , RenderingOptions , IDevice ,     )
   at    .      (IDevice ,     )
   at   .()
   at   .MoveNext()
   at    .      (Renderer ,    [] , IDevice , TimeSpan )
   at Aspose.Html.Rendering.HtmlRenderer.(IDevice , TimeSpan , Element[] , Document[] )
   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)
   at ApplicationController.<Print>d__49.MoveNext() in 
1 Like

@mklieber

Would you please share your sample HTML in .zip format or source of the HTML which you are trying to convert at your side? We will test the scenario in our environment and address it accordingly.

Sample Html.zip (172.2 KB)

1 Like

@mklieber

We tested the scenario with Aspose.HTML for .NET 20.12 and did not notice any exception. However, we observed that the program consumed all available memory and program hung up. Therefore, we have logged an issue as HTMLNET-2899 in our issue tracking system for the sake of more investigation. 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.

1 Like