DinkToPdf icon indicating copy to clipboard operation
DinkToPdf copied to clipboard

Unhandled exception. System.DllNotFoundException: Unable to load shared library

Open pajarnas opened this issue 2 years ago • 1 comments

Error output: Unhandled exception. System.DllNotFoundException: Unable to load shared library '/app/wkhtmltox/v0.12.4/x_64/libwkhtmltox.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: /app/wkhtmltox/v0.12.4/x_64/libwkhtmltox.so: cannot open shared object file: No such file or directory

My Docker File:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS builder
WORKDIR /app
COPY . .

RUN dotnet publish ./src/Api/Api.csproj -c Debug -o /app/out -f net5.0
FROM mcr.microsoft.com/dotnet/aspnet:5.0
# Install System.Drawing dependencies
 
# RUN apk add --no-cache tzdata
RUN apk add \
        --no-cache \
        --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ \
        libgdiplus
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:61065
EXPOSE 61065
COPY --from=builder /app/out .
COPY ./corp_root_ca.crt /etc/ssl/certs/corp_root_ca.pem
ENTRYPOINT ["dotnet", "My.dll"]

StartUp.cs:

    // Add pdf singletons

         var architectureFolder = (IntPtr.Size == 8) ? "x_64" : "x_86";
         var wkHtmlToPdfFileName = "libwkhtmltox";
         if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
         {
             wkHtmlToPdfFileName += ".so";
         }
         else
         {
             wkHtmlToPdfFileName += ".dll";
         }
         var wkHtmlToPdfPath = Path.Combine(
             new string[] {
                 this.Environment.ContentRootPath,
                 "wkhtmltox",
                 "v0.12.4",
                 architectureFolder,
                 wkHtmlToPdfFileName
             });
         CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
         context.LoadUnmanagedLibrary(wkHtmlToPdfPath);
         services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));

Server os: CentOS 7

Description: Working fine at local. It wont load at stage environment.

pajarnas avatar Dec 15 '21 20:12 pajarnas

Try adding this package too: https://www.nuget.org/packages/DinkToPdfCopyDependencies

zamgill avatar Mar 15 '22 23:03 zamgill