The type initializer for 'Syncfusion.PdfToImageConverter.PdfiumNative' threw an exception.

Hi,
I'm encountering an error while working with the ASP.NET Core PDF Viewer Web Service example provided by Syncfusion. The error message I'm seeing is:

"The type initializer for 'Syncfusion.PdfToImageConverter.PdfiumNative' threw an exception."

I've followed the instructions provided in the GitHub repository (https://github.com/SyncfusionExamples/EJ2-PDFViewer-WebServices/tree/main/ASP.NET%20Core/PdfViewerWebService_8.0) to set up the project and also followed the instruction given in the thread (https://www.syncfusion.com/forums/151628/the-type-initializer-for-syncfusion-ej2-pdfviewer-pdfiumnative-threw-an-exception and Pdfium dll is generating on runtime within my project location (/EJ2-PDFViewer-WebServices/ASP.NET Core/PdfViewerWebService_8.0/PdfViewerWebService_8.0/wwwroot\/x64\/libpdfium.so)

. but I'm unable to resolve this issue.

Code:


publicIActionResultLoad([FromBody] Dictionary<string, string> jsonObject)

{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";
MemoryStream stream = new MemoryStream();
object jsonResult = new object();
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
if (bool.Parse(jsonObject["isFileName"]))
{
string documentPath = GetDocumentPath(jsonObject["document"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
stream = new MemoryStream(bytes);
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
stream = new MemoryStream(bytes);
}
}
jsonResult = pdfviewer.Load(stream, jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}

1 Reply

CK Chinnamunia Karthik Chinna Thambi Syncfusion Team April 3, 2024 01:39 PM UTC

Hi Ifra,


We recommend using the "Syncfusion.EJ2.PdfViewer.AspNet.Core"NuGet package, which is compatible with Windows, Linux, and OSX platforms and also, please remove the Reference path and try once.

 

If you are using the PDF Viewer with Docker in .NET 6.0 framework, please refer to the following Dockerfile and modify your Dockerfile accordingly:

 

 

If you are using the PDF Viewer with Docker in .NET 8.0 framework, please refer to the following Dockerfile and modify your Dockerfile accordingly:

 

 

If you are still facing any issues, please provide the following details, which will help us analyze further and provide assistance:

 

  • Hosted environment (Windows, Linux, or Mac) and the steps for deploying the application (using Docker or any other method).
  • Whether you are rendering the component inside a Docker container.
  • .NET framework versions.
  • If possible, provide a sample in which the reported issue occurred.

Loader.
Up arrow icon