I am running a dotnet core 3.1 app, and I am using the DinkToPdf package for the necessary reports. When I try convert I get the following error when I click on the button that calls the conversion message.
An error occured while trying to generate the report.
System.AggregateException: One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibwkhtmltox: cannot open shared object file: No such file or directory)
---> System.DllNotFoundException: Unable to load shared library 'libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibwkhtmltox: cannot open shared object file: No such file or directory
at DinkToPdf.WkHtmlToXBindings.wkhtmltopdf_init(Int32 useGraphics)
at DinkToPdf.PdfTools.Load()
at DinkToPdf.BasicConverter.Convert(IDocument document)
at DinkToPdf.SynchronizedConverter.<>n__0(IDocument document)
at DinkToPdf.SynchronizedConverter.<>c__DisplayClass5_0.<Convert>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of inner exception stack trace ---
at DinkToPdf.SynchronizedConverter.Invoke[TResult](Func`1 delegate)
at DinkToPdf.SynchronizedConverter.Convert(IDocument document)
at WEBelieve.Application.WebApi.Controllers.PortalController.AppReportController.GenerateReportFromHtmlStringV2(String html) in /App/Controllers/PortalController/AppReportController.cs:line 668
at WEBelieve.Application.WebApi.Controllers.PortalController.AppReportController.GenerateJobDescriptionReport3(ReportViewModel reportViewModel) in /App/Controllers/PortalController/AppReportController.cs:line 615
My dockerfile is
# Build stage
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /App
# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out
# Runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /App
COPY --from=build-env /App/out .
# Set environment variables
ENV ASPNETCORE_URLS=http://0.0.0.0:5000
ENV ASPNETCORE_ENVIRONMENT=Development
# Expose ports
EXPOSE 80
EXPOSE 5000
EXPOSE 5001
# Start the application
ENTRYPOINT ["dotnet", "WEBelieve.Application.WebApi.dll"]
I have the dll and all the other dependendencies in my root folder enter image description here
It works when I run the app locally (running the app through the dotnet run with all settings) but when I run it through the server, either from the docker container or on stage and production. When I look into the files on the docker server container, the libwkhtmltox.dll, libwkhtmltox.dylib, and libwkhtmltox.so are in the /App directory.
I tried to update the redistribution by adding the following to my docker file
# Install the latest version of Visual C++ Redistributable
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libc6 \
&& rm -rf /var/lib/apt/lists/*
and I still got the same error.
I have this is my .csproj file
<None Update="libwkhtmltox.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="libwkhtmltox.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="libwkhtmltox.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Do you have any suggestions I could try with this?
This is what fixed the problem in the end