question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load DLL 'libwkhtmltox': The specified module could not be found. When using Nuget package

See original GitHub issue

When using the DinkToPdf Nuget package I get the error message below because it is looking for the libwkhtmltox DLL in the same folder the Nuget package DLL is in. For me using VS 2017 on Windows 10 this is:

%UserProfile%\.nuget\packages\dinktopdf\1.0.8\lib\netstandard1.6

When I either manually copy the correct libwkhtmltox DLL to this folder or include the source of the DinkToPdf project into my solution I no longer get this error. By including the project source into my solution the DinkToPdf DLL is then compiled into my output folder where it then also successfully finds the libwkhtmltox DLL.

Is it possible to resolve this issue without having to use the project source or regsvr32.exe? I see that TuesPechkin has an IDeployment interface to address this issue (see: https://github.com/tuespetre/TuesPechkin/issues/57). Is it possible to do something similar in DinkToPdf?

System.AggregateException: One or more errors occurred. (Unable to load DLL 'libwkhtmltox': The specified module could not be found. (Exception from HRESULT: 0x8007007E)) ---> System.DllNotFoundException: Unable to load DLL 'libwkhtmltox': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at DinkToPdf.WkHtmlToXBindings.wkhtmltopdf_init(Int32 useGraphics)
   at DinkToPdf.PdfTools.Load() in C:\Users\admin\Documents\DinkToPdf\src\DinkToPdf\PdfTools.cs:line 27
   at DinkToPdf.BasicConverter.Convert(IDocument document) in C:\Users\admin\Documents\DinkToPdf\src\DinkToPdf\BasicConverter.cs:line 42
   at DinkToPdf.SynchronizedConverter.<>n__0(IDocument document)
   at DinkToPdf.SynchronizedConverter.<>c__DisplayClass5_0.<Convert>b__0() in C:\Users\admin\Documents\DinkToPdf\src\DinkToPdf\SynchronizedConverter.cs:line 27
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at DinkToPdf.SynchronizedConverter.Invoke[TResult](Func`1 delegate) in C:\Users\admin\Documents\DinkToPdf\src\DinkToPdf\SynchronizedConverter.cs:line 51
   at DinkToPdf.SynchronizedConverter.Convert(IDocument document) in C:\Users\admin\Documents\DinkToPdf\src\DinkToPdf\SynchronizedConverter.cs:line 27

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:91 (18 by maintainers)

github_iconTop GitHub Comments

20reactions
rdvojmoccommented, Aug 9, 2017

Can you please add this class into your project just to test it before i put in the library?

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();
	}
}

Create and call CustomAssemblyLoadContext before you create your converter:

CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(path);

var converter = new SynchronizedConverter(new PdfTools());

Tested on Windows 10 64bit and Ubuntu LTS 16.04 64bit.

Will this work for your use case?

17reactions
joubinicommented, Jun 12, 2019

I was getting similar unable to load dll issues as above. I had no issues after switching to this fork: https://www.nuget.org/packages/RndUsr0.DinkToPdf/. I found it linked from this discussion: https://github.com/rdvojmoc/DinkToPdf/pull/18.

Hopefully this saves someone time from trying the myriad solutions listed in this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load DLL 'libwkhtmltox' or one of its dependencies
DllNotFoundException: Unable to load DLL 'libwkhtmltox' or one of its dependencies: The specified module could not be found.
Read more >
DinkToPdf dll not found libwkhtmltox
my project is just an API, frontend is not in C#, shouln't matter sincer the error is here: return this._converter.Convert(htmlToPdfDocument);.
Read more >
[Solved]-System.DllNotFoundException: 'Unable to load DLL ...
Coding example for the question System.DllNotFoundException: 'Unable to load DLL 'libwkhtmltox': The specified module could not be found.
Read more >
Convert html to PDF Unable to load DLL 'wkhtmltox.dll'
Unable to load DLL 'wkhtmltox.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at PFE.Internet.
Read more >
LibWkHtmlToX-32 0.12.6.1
Native library for rendering HTML into PDF and various image formats. There are no supported framework assets in this package.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found