DinkToPdf
DinkToPdf copied to clipboard
Docker Image Error on arm64 Linux EC2 Instance
I am currently using a package in my application, which functions seamlessly on my system and an x64 Linux server. However, as part of our cost optimization efforts, we are planning to migrate our application to an arm64 EC2 instance.
During the process of running the Docker image on arm64, we encountered the following error:
Unhandled exception. System.DllNotFoundException: Unable to load shared library '/app/libwkhtmltox.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: /app/libwkhtmltox.so: cannot open shared object file: No such file or directory
The Dockerfile used in our project is as follows:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus libxrender1
#RUN apt-get install -y fonts-lato
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["src/project/project.csproj"]
#RUN dotnet restore "src/project.csproj"
COPY . .
WORKDIR "/src/src/project"
#RUN dotnet build "project.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "project.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "project.dll", "--environment=Development"]
We've explored several solutions to resolve this issue without success. Could you please help us identify and address the problem? Is there any commercial support available from your side? We are open to discussing potential solutions that align with our needs.
+1 me too. 25/1/2024 I use in macbook. Need Help!
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
this issue happen because it cant find libwhtmltox
you can find in git repo file the lib, there are 3 files
- libwhtmltox.dll <- for windows
- libwhtmltox.so <- for linux
- libwhtmltox.dylib <- for mac
you need to create class
internal class CustomAssemblyLoadContext : AssemblyLoadContext
{
public IntPtr LoadUnmanagedLibrary(string absolutePath)
{
return LoadUnmanagedDll(absolutePath);
}
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
return LoadUnmanagedDllFromPath(unmanagedDllName);
}
protected override Assembly Load(AssemblyName assemblyName)
{
throw new NotImplementedException();
}
}
and in program.cs
string libraryPath = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Load .dll for Windows
libraryPath = "libwkhtmltox.dll";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Load .so for Linux
libraryPath = "libwkhtmltox.so";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// Load .dylib for macOS
libraryPath = "libwkhtmltox.sylib";
}
var loadContext = new CustomAssemblyLoadContext();
var fullpath = Path.Combine(Directory.GetCurrentDirectory(), libraryPath);
IntPtr libraryHandle = loadContext.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), libraryPath));
// Pastikan library berhasil dimuat
if (libraryHandle == IntPtr.Zero)
{
Console.WriteLine("Failed to load the library.");
return;
}
Console.WriteLine("Library loaded successfully.");
hope you can solve it