Internal CLR Error (0x80131506) with HtmlToPdfConverter after upgrading to .NET 8 RC1

Hello everyone,

After upgrading from .NET 7 to .NET 8 RC, I've encountered an issue when using the HtmlToPdfConverter. The error I'm facing is an internal CLR error: (0x80131506).

Error :

Fatal error. Internal CLR error. (0x80131506)

   at System.Runtime.Serialization.SerializationGuard.<ThrowIfDeserializationInProgress>g__ThrowIfDeserializationInProgress|0_0(System.Runtime.Serialization.SerializationInfo, System.String, Int32 ByRef)

   at System.Diagnostics.Process.Start()

   at Syncfusion.HtmlConverter.Blink.LauncherBase+State+StartingState+<StartCoreAsync>d__5.MoveNext()

   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Syncfusion.HtmlConverter.Blink.LauncherBase+State+StartingState+<StartCoreAsync>d__5, Syncfusion.HtmlConverter.Portable, Version=23.1.36.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]](<StartCoreAsync>d__5 ByRef)

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Syncfusion.HtmlConverter.Blink.LauncherBase+State+StartingState+<StartCoreAsync>d__5, Syncfusion.HtmlConverter.Portable, Version=23.1.36.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]](<StartCoreAsync>d__5 ByRef)

   at Syncfusion.HtmlConverter.Blink.LauncherBase+State+StartingState.StartCoreAsync(Syncfusion.HtmlConverter.Blink.LauncherBase)

   at Syncfusion.HtmlConverter.Blink.LauncherBase+State+StartingState.EnterFromAsync(Syncfusion.HtmlConverter.Blink.LauncherBase, State)

   at Syncfusion.HtmlConverter.Blink.LauncherBase+State+InitialState.StartAsync(Syncfusion.HtmlConverter.Blink.LauncherBase)

   at Syncfusion.HtmlConverter.Blink.LauncherBase.StartAsync()

   at Syncfusion.HtmlConverter.Blink.Launcher+<LaunchAsync>d__4.MoveNext()

   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Syncfusion.HtmlConverter.Blink.Launcher+<LaunchAsync>d__4, Syncfusion.HtmlConverter.Portable, Version=23.1.36.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]](<LaunchAsync>d__4 ByRef)

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Syncfusion.HtmlConverter.Blink.Launcher+<LaunchAsync>d__4, Syncfusion.HtmlConverter.Portable, Version=23.1.36.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]](<LaunchAsync>d__4 ByRef)

   at Syncfusion.HtmlConverter.Blink.Launcher.LaunchAsync(Syncfusion.HtmlConverter.Blink.LaunchOptions)

   at Syncfusion.HtmlConverter.BlinkConverter+<ConvertAsync>d__221.MoveNext()

   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Syncfusion.HtmlConverter.BlinkConverter+<ConvertAsync>d__221, Syncfusion.HtmlConverter.Portable, Version=23.1.36.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]](<ConvertAsync>d__221 ByRef)

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Syncfusion.HtmlConverter.BlinkConverter+<ConvertAsync>d__221, Syncfusion.HtmlConverter.Portable, Version=23.1.36.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]](<ConvertAsync>d__221 ByRef)

   at Syncfusion.HtmlConverter.BlinkConverter.ConvertAsync(System.String)

   at Syncfusion.HtmlConverter.BlinkConverter.ConvertToPdf(System.String, Syncfusion.Pdf.PdfDocument ByRef)

   at Syncfusion.HtmlConverter.BlinkConverter+<>c__DisplayClass202_0.<Convert>b__0()

   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)


My code :

public class PDFService : IPDFService
{
public async Task<byte[]?> FromHtmlAsync(string html, string? baseUrl = null)
{
if (string.IsNullOrEmpty(html))
return null;

//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

BlinkConverterSettings settings = new BlinkConverterSettings();

//Set command line arguments to run without sandbox.
settings.CommandLineArguments.Add("--no-sandbox");
settings.CommandLineArguments.Add("--disable-setuid-sandbox");
// Set page size of PDF document
settings.PdfPageSize = PdfPageSize.A4;

//Assign Blink settings to HTML converter
htmlConverter.ConverterSettings = settings;

//Convert URL to PDF
PdfDocument document = htmlConverter.Convert(html, baseUrl);

var fileStream = new MemoryStream();
document.Save(fileStream);
var pdfBytes = fileStream.ToArray();
document.Close(true);

return pdfBytes;
}
}


The error wasn't present when I was using .NET 7.

Additionally, I'd like to mention that I'm facing this error when running my application inside a Docker (Linux) container as well.

Thank you in advance for your time and support.

Best regards,


6 Replies 1 reply marked as answer

SN Santhiya Narayanan Syncfusion Team September 19, 2023 01:49 PM UTC

We have checked the reported issue in .Net 8 but it is working properly on our end. So we have attached the sample for your reference. Kindly try the sample on your end and let us know the result.

sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/linuxdocker1702846207

If still you are facing the issue, we request you to share the modified sample, environment details (OS, bit version, culture settings, RAM size, etc.,), input html to check this on our end. So that it will be helpful for us to analyze and assist you further on this.




Rémi September 21, 2023 10:52 AM UTC

Hello,


Thanks for your response.


In 'Debug' mode it works, but I get a similar problem when I activate 'Release' mode:


fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]

      An unhandled exception has occurred while executing the request.

      Syncfusion.Pdf.PdfException: Failed to convert webpage

       ---> Syncfusion.Pdf.PdfException: Failed to convert webpage

         at Syncfusion.HtmlConverter.BlinkConverter.BlinkResult(Stream outputStream)

         at Syncfusion.HtmlConverter.BlinkConverter.ConvertToPdf(String url, PdfDocument& document)

         --- End of inner exception stack trace ---

         at Syncfusion.HtmlConverter.BlinkConverter.Convert(String url)

         at Syncfusion.HtmlConverter.BlinkConverter.Convert(String htmlString, String baseurl)

         at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String html, String baseurl)

         at linuxdocker.Controllers.HomeController.ExportToPDF() in /src/linuxdocker/Controllers/HomeController.cs:line 44

         at lambda_method18(Closure, Object, Object[])

         at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()

         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

      --- End of stack trace from previous location ---

         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()

      --- End of stack trace from previous location ---

         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()

      --- End of stack trace from previous location ---

         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)

         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)

         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)

         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)


Regards




KS Karmegam Seerangan Syncfusion Team September 22, 2023 02:04 PM UTC

Hi Rémi,


Currently, We are checking the reported issue with provided details on our end and will update you further details on September 26,2023.


Regards,

Karmegam



KS Karmegam Seerangan Syncfusion Team September 26, 2023 01:45 PM UTC

On further analysis, the reported issue occurs due to a permission-related issue in the release configuration. We are internally launching Chromium for HTML-to-PDF conversion. But we are unable to launch Chromium due to a permission issue in the release configuration environment. We can overcome this issue by adding the ‘runtimes/linux/native’ folder to the project application and setting ‘copy always’. We have attached the working sample for your reference. Kindly try the attached sample on your end and let us know the result.


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/linuxdocker-1527237875


Please refer the below screenshot,



Rémi October 14, 2023 01:06 PM UTC

Hello,

Thank you.

I apologize for my delayed response. I've just reviewed the issue and found a less restrictive solution than including the runtime files in the project. In the "Dockerfile", you just need to add the following lines (before the ENTRYPOINT [...]):


USER root
RUN chmod +x /app/runtimes/linux/native/chrome
RUN chmod +x /app/runtimes/linux/native/chrome_sandbox
RUN chmod +x /app/runtimes/linux/native/chrome-wrapper
USER app


I hope this solution is suitable and doesn't introduce any security concerns or other issues.

Regards.


Marked as answer

KS Karmegam Seerangan Syncfusion Team October 16, 2023 11:14 AM UTC

We are glad that you found the solution, please get back to us if you need any other assistance.


Loader.
Up arrow icon