PDF Viewer Service died after .Net 6 upgrade

Hi,

I have a ASP.NET Core app that has a controller that serves my Blazor client app for .pdf-files. The controller is set up as one of your documents suggests. It was working fine until i upgraded my server and client apps to .net 6. The "Load" and "RenderPDFPages" endpoints are hit correctly but the "pdfviewer.GetPage(jsonObject);" call in  "RenderPDFPages" endpoint results string object with value "The type initializer for 'Gdip' threw an exception."

I'm guessing that there might be something wrong with my docker image generation. Here's current dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base

ARG ENVIRONMENT=Release

ENV ASPNETCORE_ENVIRONMENT=$ENVIRONMENT

RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list

RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

RUN apt-get update \

    && apt-get install -y --allow-unauthenticated \

        libc6-dev \

        libgdiplus \

        libx11-dev \

        curl \

        vim \

        supervisor \

        procps


Any suggestions to fix this? Why those methods in used in the pdf viewer controller doesn't throw on exceptions? Only visible indication that i get from these kind of errors is that i get the pdf viewer in the client app prompt that same generic message of pdf viewer depending on server. Would be lot better if those endpoints would throw or that the client component would indicate that server produced error.

Current syncfusion version is 19.3.0.53 for all libraries.

-Ville



6 Replies 1 reply marked as answer

DM Dhivyabharathi Mohan Syncfusion Team November 15, 2021 11:57 AM UTC

Hi Ville, 
 
Thank you for contacting Syncfusion support. 
  
Please find the details, 
 
 
Query 
Details 
 
I have a ASP.NET Core app that has a controller that serves my Blazor client app for .pdf-files. The controller is set up as one of your documents suggests. It was working fine until i upgraded my server and client apps to .net 6. The "Load" and "RenderPDFPages" endpoints are hit correctly but the "pdfviewer.GetPage(jsonObject);" call in  "RenderPDFPages" endpoint results string object with value "The type initializer for 'Gdip' threw an exception." 
I'm guessing that there might be something wrong with my docker image generation. Here's current dockerfile: 
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base 
ARG ENVIRONMENT=Release 
ENV ASPNETCORE_ENVIRONMENT=$ENVIRONMENT 
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list 
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig 
RUN apt-get update \ 
    && apt-get install -y --allow-unauthenticated \ 
        libc6-dev \ 
        libgdiplus \ 
        libx11-dev \ 
        curl \ 
        vim \ 
        supervisor \ 
        procps 
Any suggestions to fix this? 
 
 
We have embedded the Pdfium rendering engine in our PDF Viewer for robust rendering, we will create the pdfium.dll based on the operating system during the runtime of the control.  So pdfium.dll (libpdfium.so) will be generated on runtime within the project location. Please ensure whether the libpdfium.so is generated properly on your end. And we internally using System.Drawing, it requires libgdiplus to run properly in Linux environment. To work with PDFIUM in the LINUX environment we need to add the following commands in the docker file to install dependencies.  
  
RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so  
# install System.Drawing native dependencies  
RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus libc6-dev libx11-dev  
RUN ln -s libgdiplus.so gdiplus.dll  
  
Need to execute the following command to install the dependencies.   
  
  
sudo apt install libc6-dev
sudo apt install libgdiplus 
  
  
  
However, in .NET 6, the System.Drawing.Common NuGet package is only supported on Windows operating systems. Internally we have used the System.Drawing to process the implementation. So, the reported issue occurs on your Linux container.  
  
Please refer to the below links.  
 
 
 
 
 
Why those methods in used in the pdf viewer controller doesn't throw on exceptions? Only visible indication that i get from these kind of errors is that i get the pdf viewer in the client app prompt that same generic message of pdf viewer depending on server. Would be lot better if those endpoints would throw or that the client component would indicate that server produced error. 
Current syncfusion version is 19.3.0.53 for all libraries. 
 
 
 
You can use the showNotificationDialog property to hide the default notification dialog. And you can use the ajaxRequestFailed event to display the error message in the dialog box by using the given code snippet. We have shared the code snippet for your reference. 
 
Code snippet: 
 
<ejs-pdfviewer id="pdfviewer1" serviceUrl="/api/PdfViewer" documentPath="HTTP Succinctly.pdf" ajaxRequestFailed = "ajaxRequestFailed" showNotificationDialog ="false"></ejs-pdfviewer> 
 
 
function ajaxRequestFailed(args) { 
    var viewer = document.getElementById('pdfviewer1').ej2_instances[0]; 
        var errorMessage = "Exception thrown as “The type initializer for 'Gdip' threw an exception"; 
    viewer.showNotificationPopup(errorMessage); 
    } 
 
 
Kindly try this and revert us, if you have any concerns. 
 
 
 
 
Regards, 
Dhivya. 



VI Ville replied to Dhivyabharathi Mohan November 16, 2021 11:25 AM UTC

Thanks for your reply.


I managed to regain APIs functionality to handle PDF-files. I did as suggested in the second link you provided and added a runtimeconfig.template.json -file to my API project root with content:

{

    "configProperties": {

      "System.Drawing.EnableUnixSupport": true

    }

}

However as stated in the article, they might drop all support in future for System.Drawing.Common library in non-windows systems. Any plans to update your library not to use it and keep everything cross platform as it should be?


br. Vil



Marked as answer

DM Dhivyabharathi Mohan Syncfusion Team November 17, 2021 07:50 AM UTC

Hi Ville, 
 
Thank you for the update. We will consider making an alternative plan based on the update in the future. Please revert to us, if you need further assistance. 
 
Regards, 
Dhivya. 



NB Nyron Burke February 18, 2022 11:19 PM UTC

I ran into the same issue and would like to also request that this be updated



DM Dhivyabharathi Mohan Syncfusion Team February 21, 2022 06:55 AM UTC

Hi Nyron, 
  
  
Currently we are working to replace the System.Drawing by the alternative package mentioned in the following link, 
 
 
We will complete these changes and include the changes in our upcoming main release Volume 1, 2022 and it will be expected end of March 2022. You can track the status using the below feedback link, 


 
 
 
Regards, 
Dhivya. 



VS Vasugi Sivajothi Syncfusion Team April 4, 2022 02:58 PM UTC

Hi Nyron,


We are glad to announce that our Essential Studio 2022 Volume 1 Main Release V20.1.0.47 is rolled out and is available for download under the following link.


We have implemented the feature implementation and it was included in our volume release V20.1.0.47. Kindly upgrade to that version.


https://www.syncfusion.com/forums/174125/essential-studio-2022-volume-1-main-release-v20-1-0-47-is-available-for-download


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.


Regards,

Vasugi


Loader.
Up arrow icon