Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies #179

Open
svap-roshan opened this issue Jun 30, 2023 · 3 comments

Comments

@svap-roshan
Copy link

Currently, I am using a Linux container, and I encountered the following error: "One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies)"

I have included the stack trace for further analysis.

System.DllNotFoundException: Unable to load shared library 'libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/app/runtimes/linux-arm64/native/libwkhtmltox.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/libwkhtmltox.so: cannot open shared object file: No such file or directory
/app/libwkhtmltox.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-arm64/native/liblibwkhtmltox.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/liblibwkhtmltox.so: cannot open shared object file: No such file or directory
/app/liblibwkhtmltox.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-arm64/native/libwkhtmltox: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/libwkhtmltox: cannot open shared object file: No such file or directory
/app/libwkhtmltox: cannot open shared object file: No such file or directory
/app/runtimes/linux-arm64/native/liblibwkhtmltox: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/liblibwkhtmltox: cannot open shared object file: No such file or directory
/app/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.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 ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

Here is the code from my Dockerfile, along with the various packages I have tried in my attempts to resolve the issue.

FROM mcr.microsoft.com/dotnet/aspnet:7.0.8-bullseye-slim-arm64v8 AS base
RUN apt-get update
RUN apt-get install -y --allow-unauthenticated libgdiplus
RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y
RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y
WORKDIR /app
EXPOSE 80
# copy csproj and restore as distinct layers
FROM mcr.microsoft.com/dotnet/sdk:7.0.305-bullseye-slim-arm64v8 AS build
WORKDIR /src
COPY *.sln .
COPY ["PdfApp/PdfApp.csproj", "PdfApp/"]
RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll
RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib
RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so
RUN dotnet restore "PdfApp/PdfApp.csproj"
# copy and publish app and libraries
COPY . .
WORKDIR "/src/PdfApp"
RUN dotnet build "PdfApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PdfApp.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PdfApp.dll"]

The application functions properly when hosted in IIS, but encounters issues when running within a linux container.
Below DLL are present in the root directory.

libwkhtmltox.dll
libwkhtmltox.dylib
libwkhtmltox.so

@novocodev
Copy link

Did you find a solution to this, I'm having exactly the same issue on linux

@svap-roshan
Copy link
Author

@novocodev The issue lay with my previous docker image, where I was using Debian. However, after switching to Ubuntu, the problem was resolved, and the new configuration works seamlessly. Below is my Docker file; I hope it proves useful to you. Also please make sure you have the libwkhtmltox.dll, libwkhtmltox.dylib and libwkhtmltox.so in your root directory.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus
ENV ASPNETCORE_ENVIRONMENT Production
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY *.sln .
COPY ["PdfApp/PdfApp.csproj", "PdfApp/"]
RUN dotnet restore "PdfApp/PdfApp.csproj"
# copy and publish app and libraries
COPY . .
WORKDIR "/src/PdfApp"
RUN dotnet build "PdfApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PdfApp.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PdfApp.dll"]

@Seba2471
Copy link

Seba2471 commented May 26, 2024

I have fixed this problem in .NET 8

Needed below lines of code to dockerfile between:
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
RUN apt-get update
RUN apt-get install -y --allow-unauthenticated libgdiplus
RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y
RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y

USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

And need to have the libwkhtmltox.dll, libwkhtmltox.dylib and libwkhtmltox.so in your root directory and additional links below in the .csproj file:

	<ItemGroup>
		<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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants