DinkToPdf
DinkToPdf copied to clipboard
Unable to load DLL 'libwkhtmltox' or one of its dependencies
Request ID: System.AggregateException: One or more errors occurred. (Unable to load DLL 'libwkhtmltox' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)) ---> System.DllNotFoundException: Unable to load DLL 'libwkhtmltox' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
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.Task1.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) --- End of inner exception stack trace --- at DinkToPdf.SynchronizedConverter.Invoke[TResult](Func
1 delegate)
at DinkToPdf.SynchronizedConverter.Convert(IDocument document)
at GymCore.Controllers.RegistrationController.CreatePDF(Int32 regno) in C:\Users\UDN002\Desktop\GymCore\GymCore\Controllers\RegistrationController.cs:line 489
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context) ---> (Inner Exception #0) System.DllNotFoundException: Unable to load DLL 'libwkhtmltox' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) 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)<---
Still facing the issue can you please help :
I have set the properties of libwkhtmltox.dll
I tried the both the both debug & release.
I'm stuck please help
What you might be experiencing could be a misleading error message, if you don't have the VSRedist 2015 package installed on the machine/server. (typical for use of c++ libraries)
You could try using my powershell module to detect/silently install the redistributable package: PowershellVsRedistInstaller
You can also just check the powershell code to find where to check in the registry or check where to download the files.
Hello, Check the answer from here.
https://stackoverflow.com/questions/55430532/dinktopdf-net-core-not-able-to-load-dll-files.
I used that and it worked very well.
In my case it is working in local but when I'm trying to publish in azure its throwing the following error and failing the whole application An error occurred while starting the application. DllNotFoundException: Unable to load DLL 'D:\home\site\wwwroot\bin\Debug\netcoreapp2.0\libwkhtmltox': The specified module could not be found. (Exception from HRESULT: 0x8007007E) System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(string unmanagedDllPath)
DllNotFoundException: Unable to load DLL 'D:\home\site\wwwroot\bin\Debug\netcoreapp2.0\libwkhtmltox': The specified module could not be found. (Exception from HRESULT: 0x8007007E) System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(string unmanagedDllPath) System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDllFromPath(string unmanagedDllPath) Socrates.ApiServices.Startup+CustomAssemblyLoadContext.LoadUnmanagedDll(string unmanagedDllName) in Startup.cs Socrates.ApiServices.Startup.ConfigureServices(IServiceCollection services) in Startup.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services) Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
It's nice work for me:
using System;
using System.Reflection;
using System.Runtime.Loader;
public 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 before initialize Converter call this one:
new CustomAssemblyLoadContext().LoadUnmanagedLibrary($"{pathToYour-libwkhtmltox.dll}/libwkhtmltox.dll");
===>AssemblyLoadContext you can install from nuget System.Runtime.Loader ===>libwkhtmltox.dll you can download here: https://github.com/rdvojmoc/DinkToPdf/tree/master/v0.12.4
download this on server, where you try to use libwkhtmltox.dll https://support.microsoft.com/ru-ru/help/2977003/the-latest-supported-visual-c-downloads
Having this issue on an azure function. Has anyone gotten this to work in an azure function?
We're running this in a function app, to me it looks like you're pointing to the wrong path.
In our case (where the packages are deployed from nuget and part of the build deployed as a package in the function app) it would be something like: D:\home\site\wwwroot\bin
the files would be located in. Let me know if this helps.
It's also worth mentioning that the service plan the app service or function is using cannot be the free tier, runs just fine on S1 (provided all the paths to the executables are correct)
I think that was my issue. Ended up going another route. Still using an azure function but went with a node package instead. The critical thing to point out is that in the consumption plan you dont have access to GDI support in the sandbox. https://stackoverflow.com/questions/61473525/node-return-byte-array-after-turning-html-to-pdf
download this on server, where you try to use libwkhtmltox.dll https://support.microsoft.com/ru-ru/help/2977003/the-latest-supported-visual-c-downloads
It's worked. Thanks bro
I solved this problem more quickly.
Solution: Add these codes inside the Project.Service.csproj
<ItemGroup>
<None Remove="libwkhtmltox.dll" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="libwkhtmltox.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
Thanks @dgokhan. Adding the given code to the project's .csproj file worked for me.
I needed to solve this without installing any packages. I managed to solve it by downloading all 3 files (dll, dylib and so) and putting them into the project directory. Then I added this into the .csproj file:
<ItemGroup> <None Update="libwkhtmltox.dll"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> </None> <None Update="libwkhtmltox.dylib"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> </None> <None Update="libwkhtmltox.so"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> </None> </ItemGroup>
@dgokhan method worked for me. All I had to in addition for it work remotely was placing the libwkhtmltox.dll in the remote server.
I have lost a number of hours trying to resolve this issue on OSX and have finally found the solution which is quite obvious in hindsight. Hopefully it helps someone in the future.
Windows reference - libwkhtmltox.dll OSX reference - libwkhtmltox.dylib Linux reference - libwkhtmltox.os
Obviously make you you reference the correct file for your OS.
https://githubmemory.com/repo/rdvojmoc/DinkToPdf/issues/100
Download package from https://github.com/rdvojmoc/DinkToPdf/tree/master/v0.12.4
Add it to your project reference by custom Assembly reference & register in your startup project. This is custom assembly load context which can load library from absolute path.
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();
}
}
In Statup.cs add below code. Call CustomAssemblyLoadContext before you create your converter:
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(path);
var converter = new SynchronizedConverter(new PdfTools()); services.AddSingleton(converter); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
Hi Team,
I am also facing the same issue with .Net.Core 5.I resolved the issue while doing the below steps.
1.Docker file need to add the below things. RUN apt-get update RUN apt-get install -y wget RUN apt-get install -y curl
RUN cd /app
RUN apt-get update
&& apt-get install -y --no-install-recommends
zlib1g
fontconfig
libfreetype6
libx11-6
libxext6
libxrender1
&& curl -o /usr/lib/libwkhtmltox.so
--location
https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so
RUN wget https://github.com/rdvojmoc/DinkToPdf/blob/master/v0.12.4/64%20bit/libwkhtmltox.dll RUN wget https://github.com/rdvojmoc/DinkToPdf/blob/master/v0.12.4/64%20bit/libwkhtmltox.dylib RUN wget https://github.com/rdvojmoc/DinkToPdf/blob/master/v0.12.4/64%20bit/libwkhtmltox.so WORKDIR /app COPY --from=publish /app .
- Don't add any assembly in solution level.
- if you need to local debug # if DEBUG then add dll in project.
- This below code in startup.cs file for local debug.
if DEBUG
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll"));
var converter = new SynchronizedConverter(new PdfTools());
services.AddSingleton(converter);
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
#Endif Thanks, Manish
If this is important for someone, I add the code like in the previous answers, additionally when I tried to publish my app there was the error 500.30 because the architecture in the azure portarl, so change the platform for 64bits or 32bits and thats all.