title: HtmlRenderer.PdfSharp Message = "Index was outside the bounds of the array."
body: <p>I try convert HTML to PDF with <code>HtmlRenderer.PdfSharp</code>. My code for converting:</p>
  
  <pre><code>byte[] bytes;
  var html = File.ReadAllText(htmlFilePath);
  
  using (MemoryStream ms = new MemoryStream())
  {
      var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A3);
      pdf.Save(ms);
      bytes = ms.ToArray();
  }
  
  File.WriteAllBytes(outputFilePath, bytes);
  </code></pre>
  
  <p>When I trying to generate PDF from <code>GeneratePdf</code> method I get an exception:</p>
  
  <blockquote>
    <p>Index was outside the bounds of the array.</p>
  </blockquote>
  
  <p>Stack trace:</p>
  
  <blockquote>
    <p>at
    TheArtOfDev.HtmlRenderer.Core.Parse.RegexParserUtils.GetCssAtRules(String
    stylesheet, Int32&amp; startIdx)    at
    TheArtOfDev.HtmlRenderer.Core.Parse.CssParser.ParseMediaStyleBlocks(CssData
    cssData, String stylesheet)    at
    TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox
    box, HtmlContainerInt htmlContainer, CssData&amp; cssData, Boolean&amp;
    cssDataChanged)    at
    TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox
    box, HtmlContainerInt htmlContainer, CssData&amp; cssData, Boolean&amp;
    cssDataChanged)    at
    TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox
    box, HtmlContainerInt htmlContainer, CssData&amp; cssData, Boolean&amp;
    cssDataChanged)    at
    TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox
    box, HtmlContainerInt htmlContainer, CssData&amp; cssData, Boolean&amp;
    cssDataChanged)    at
    TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.GenerateCssTree(String
    html, HtmlContainerInt htmlContainer, CssData&amp; cssData)    at
    TheArtOfDev.HtmlRenderer.Core.HtmlContainerInt.SetHtml(String
    htmlSource, CssData baseCssData)    at
    TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(String
    html, PdfGenerateConfig config, CssData cssData, EventHandler<code>1
    stylesheetLoad, EventHandler</code>1 imageLoad) in
    d:\source\github\HTML-Renderer\Source\HtmlRenderer.PdfSharp\PdfGenerator.cs:line
    122    at
    Plutora.Common.PhantomJS.PhantomRunner.ConvertHTMLtoPDF(String
    pdfOutputLocation, String outputFilenamePrefix, String[] urls)    at
    Plutora.Common.PhantomJS.PhantomRunner.HtmlToPdf(String
    pdfHtmlToPdfExePath, String pdfOutputLocation, String
    outputFilenamePrefix, String[] urls, String runOptionsFormat, String
    runOptionsOrientation)</p>
  </blockquote>
  
  <p>I have local HTML file with  inline CSS and absolutely linked CSS. </p>
  
  <p>Why I get that exception? How to solve it?</p>