While converting word document to Pdf in linux container.Exception thrown The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.

Exception details:
The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.   at Syncfusion.Drawing.SkiaSharpHelper.Image..ctor(Int32 width, Int32 height)
   at Syncfusion.Drawing.SkiaSharpHelper.Bitmap..ctor(Int32 width, Int32 height)
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext..ctor()
   at Syncfusion.DocIORenderer.DocIORenderer.ConvertToPDF(WordDocument wordDocument)
   at Voyager.DocumentTemplateProcessor.Business.Util.ProcessTemplateUtil.CovertPdfStreamToBase64(WordDocument document)

It's working on the Windows system but not in the Linux docker container.

Doker file:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
RUN apt-get update && apt-get install -y libgdiplus
RUN apt-get update && apt-get install -y libfontconfig1
WORKDIR /app
EXPOSE 80


FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["DocumentTemplateProcessor.API/DocumentTemplateProcessor.API.csproj", "DocumentTemplateProcessor.API/"]
COPY ["DocumentTemplateProcessor.Business/DocumentTemplateProcessor.Business.csproj", "DocumentTemplateProcessor.Business/"]
COPY ["DocumentTemplateProcessor.DataAccess/DocumentTemplateProcessor.DataAccess.csproj", "DocumentTemplateProcessor.DataAccess/"]
COPY ["DocumentTemplateProcessor.Common/DocumentTemplateProcessor.Common.csproj", "DocumentTemplateProcessor.Common/"]
RUN dotnet restore "DocumentTemplateProcessor.API/DocumentTemplateProcessor.API.csproj"
COPY . .
WORKDIR "/src/DocumentTemplateProcessor.API"
RUN dotnet build "DocumentTemplateProcessor.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DocumentTemplateProcessor.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DocumentTemplateProcessor.API.dll"]

Nuget Packages:

   <PackageReference Include="SkiaSharp" Version="2.80.3-preview.18" />
    <PackageReference Include="SkiaSharp.Linux" Version="1.59.3" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.3-preview.18" />
    <PackageReference Include="Syncfusion.DocIO.Net.Core" Version="18.4.0.34" />
    <PackageReference Include="Syncfusion.EJ2.WordEditor.AspNet.Core" Version="18.4.0.34" />
    <PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="18.4.0.34" />
    <PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="18.4.0.34" />
    <PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.9" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="Syncfusion.Pdf.Net.Core" Version="18.4.0.34" />

3 Replies 1 reply marked as answer

MJ Mohanaselvam Jothi Syncfusion Team January 15, 2021 02:00 PM UTC

Hi hardik,

Thank you for contacting Syncfusion support.

We suspect that the issue might be due to SkiaSharp references in your project. We suggest you to remove all the SkiaSharp references and use SkiaSharp.NativeAssets.Linux v2.80.2 NuGet alone to perform Word to PDF in Linux Docker. Please refer the below link to know more about Word to PDF in Linux environment:
https://help.syncfusion.com/file-formats/docio/word-to-pdf#word-to-pdf-conversion-in-linux-os

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



SE Selva May 26, 2021 08:48 AM UTC

Hi,

Still its not resolved...

 The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
syncfusionapi_1  |    at Syncfusion.Drawing.SkiaSharpHelper.Image..ctor(Int32 width, Int32 height)
syncfusionapi_1  |    at Syncfusion.Drawing.SkiaSharpHelper.Bitmap..ctor(Int32 width, Int32 height)
syncfusionapi_1  |    at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext..ctor()
syncfusionapi_1  |    at Syncfusion.DocIORenderer.DocIORenderer.ConvertToPDF(WordDocument wordDocument)
syncfusionapi_1  |    at SyncfusionAPI.Controllers.SyncfusionController.ConvertToPDF(IFormCollection data) in /src/Controllers/SyncfusionController.cs:line 119


<PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
    <DockerComposeProjectPath>docker-compose.dcproj</DockerComposeProjectPath>
    <UserSecretsId>b885d2c1-283c-4a84-b764-923571212bd8</UserSecretsId>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.13" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
    <PackageReference Include="Syncfusion.DocIO.Net.Core" Version="19.1.0.65" />
    <PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="19.1.0.64" />
    <PackageReference Include="Syncfusion.EJ2.WordEditor.AspNet.Core" Version="19.1.0.57" />
    <PackageReference Include="Syncfusion.Licensing" Version="19.1.0.65" />
    <PackageReference Include="Syncfusion.Pdf.Net.Core" Version="19.1.0.64" />  
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="18.4.0.34" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.9" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
  
  </ItemGroup>


Thanks
Selva


HC Hemalatha Chiranjeevulu Syncfusion Team May 27, 2021 12:06 PM UTC

Hi Selva,

Thank you for your update.

We tried to reproduce the reported exception issue using given details but, it works properly at our end. For your reference, we have attached the sample application which we used at our end to reproduce the reported exception issue and it can be downloaded from the below link

Sample link: https://www.syncfusion.com/downloads/support/forum/161495/ze/WordToPDF720171003

Could you please check and confirm us whether
you have faced mentioned exception issue in above sample also. If no, then share us the simplified sample or modified sample of above along with input Word document which used at your end to replicate the same problem. Thereby, we will proceed further to replicate the same problem at our end and will provide the more details.

Note: If you have any confidential data in your document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.

Please let us know if you have any other questions.

Regards,
Hemalatha C


Marked as answer
Loader.
Up arrow icon