-
Notifications
You must be signed in to change notification settings - Fork 422
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
Unable to load DLL 'libwkhtmltox': The specified module could not be found. When using Nuget package #5
Comments
FYI I tried using this work around to copy the nuget references to the output folder:
Source here: https://stackoverflow.com/questions/43837638/how-to-get-net-core-projects-to-copy-nuget-references-to-build-output. This copies the referenced nuget binaries to the output folder but the .net core web app still uses the dinktopdf.dll located in:
So unfortunately this doesn't work |
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? |
Thanks! And yes this works in my case. |
I have a a bit similar problem. I mean all works on my machine, but when I load my service to Azure. I try to use the html2pdf functionality and it cant load the dll. I see the dll is there and all, but not working. I tried making it build on x86, not yet with x64 as this might be the issue. Will keep you updated. The message I get is this: |
Your Azure instance is 64bit or 32bit? |
arjasepp Azure by default requires the 32 bit version. Check your Application Settings under the App Service your deploying to. See also https://serverfault.com/questions/567987/32bits-or-64bits-for-windows-azure-web-sites. Unless you're running Windows XP locally your Dev environment will require the 64 bit version which for me created quite a problem when it came to getting our solution to build correctly for Dev and also for our Azure Test and UAT environments. Because we are using a build server operating on a 64 bit OS I had to add the following to the csproj using DinkToPdf and therefore also using the WkHtmlToPdf library.
I added the WkHtmlToPdf binaries in a "lib\wkhtmltox" folder at the solution level hence the ".." parent folder traversing at the project level. |
I got something to work now. Will observe more about this. Thanks @graemehyde |
arjasepp Just a quick update in case it helps. We've changed tactic with out solution slightly to choose the correct WkHtmlToPdf binary at run time instead of at build time. To do that involves copying all of the WkHtmlToPdf binaries to the output folder (in a sub folder separated by 32 and 64 bit). The correct binary is then determined at run time and then pre-loaded using rdvojmoc's example above with the following additional code:
Note no extension (.dll, dylib, or .os) is provided as my understanding is each OS will handle this for you. My csproj to copy the WkHtmlToPdf binaries to the output folder now looks like this (note no conditions):
|
Hi, I get this error System.DllNotFoundException : 'Unable to load DLL 'libwkhtmltox' and a message saying pdftools.cs not found. |
Stan92 Things to check:
I haven't tried with .Net Core 2.0 but the error you're getting suggests to me the problem is not with .Net Core but with one of the two options above. |
@graemehyde |
Also having this problem. Just manually copying the dll into my packages folder for the time being. Any plans on this being fixed in an upcoming release? |
@JoshLefebvre Can you be more specific what do you expect to be fixed? |
anyone knows where should i put libwkhtmltox.dll in docker container? i have the file in my project, set it to copy always, i can confirm the file exist in docker container in /app and various /bin folders, but when i run app, it's giving the op's error : "Unable to load DLL 'libwkhtmltox': The specified module could not be found. |
Put it in the root directory of the project.
…On Sep 14, 2017 9:00 AM, "dragonemp" ***@***.***> wrote:
anyone knows where should i put libwkhtmltox.dll in docker container? i
have the file in my project, set it to copy always, i can confirm the file
exist in docker container in /app and various /bin folders, but when i run
app, it's giving the op's error : "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()", i have no idea where to go from here
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFO-ytN9nIeHJkvMLu9c6NH6sihx6cEaks5siJ3pgaJpZM4OxWKP>
.
|
I have it in root, still having the issue
On Wed, Sep 13, 2017, 8:49 PM Kameshwaran Sachithanantham <
[email protected]> wrote:
Put it in the root directory of the project.
On Sep 14, 2017 9:00 AM, "dragonemp" ***@***.***> wrote:
> anyone knows where should i put libwkhtmltox.dll in docker container? i
> have the file in my project, set it to copy always, i can confirm the
file
> exist in docker container in /app and various /bin folders, but when i
run
> app, it's giving the op's error : "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()", i have no idea where to go from here
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#5 (comment)>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AFO-ytN9nIeHJkvMLu9c6NH6sihx6cEaks5siJ3pgaJpZM4OxWKP
>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AUEpxImmxh91jJk1cKR-BGwPT6Wnh4RZks5siKIrgaJpZM4OxWKP>
.
--
Hai Zhao
|
Hello, If you are using Ubuntu based docker please install libgdiplus. See issue #3 . |
it's linux docker container but not ubuntu based since sudo is not a
recognized command
On Wed, Sep 13, 2017 at 9:32 PM rdvojmoc ***@***.***> wrote:
Hello,
If you are using Ubuntu based docker please install libgdiplus.
sudo apt-get install libgdiplus
See issue #3 <#3> .
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AUEpxMBX3FNdFVuRdHPnWOcdXVxba9G_ks5siKxVgaJpZM4OxWKP>
.
--
Hai Zhao
|
i began to wonder if it's 32/64 bit issue, where do i find different
version of libwkhtmltox dll?
On Wed, Sep 13, 2017 at 9:35 PM Hai Zhao ***@***.***> wrote:
it's linux docker container but not ubuntu based since sudo is not a
recognized command
On Wed, Sep 13, 2017 at 9:32 PM rdvojmoc ***@***.***> wrote:
> Hello,
>
> If you are using Ubuntu based docker please install libgdiplus.
> sudo apt-get install libgdiplus
>
> See issue #3 <#3> .
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#5 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AUEpxMBX3FNdFVuRdHPnWOcdXVxba9G_ks5siKxVgaJpZM4OxWKP>
> .
>
--
Hai Zhao
--
Hai Zhao
|
Which OS is in the docker then? |
sorry, i'm very new to docker, thought when docker-compose object says "target OS: Linux" , it means linux, but after checking files more closely, i see the image used is microsoft aspnetcore-build 1.1, so this is windows, i checked inside docker container, the dll is definitely there, so this has to be 32 vs 64 issue right? where is the official location to get those dlls? version: '3' services: |
It's not 32/64 bit issue. If it was BadImageFormatException is thrown. |
Can I download same docker image that you have to check this myself? The problem is with one of dependencies that needs to be installed for wkhtmltopdf to work. |
yeah, that should be public available image, i just use |
Thanks, looking into it. |
what i'm doing is building a micro service for reporting, in which i generate html (was hoping to use excel, but cannot find anything to convert excel to pdf in .net core), then convert to pdf byte[] as response, it's working fine when i start it in iis express from visual studio, but if i run docker-compose to build it into docker container, i always get cannot load dll issue |
Can you please run command |
still same issue at DinkToPdf.WkHtmlToXBindings.wkhtmltopdf_init(Int32 useGraphics) |
Can I see what is getting published to docker image? |
On Linux, this can help:
|
You need install Mono https://www.mono-project.com/download/stable/ |
I thought I'd share my result after some time spent on this issue. Quick notes:
It all worked independently using the root for storing the DLLs - 64 bit for my local environment and 32 bit for the hosted Azure environment. The CustomAssemblyLoadContext would not work locally and would always give me the "Unable to load DLL 'libwkhtmltox'" message. After some experimentation, I was able to load my project specifying the extension libwkhtmltox.dylib. However, the convert method would fail as unable to find libwkhtmltox. My suspicion is that dylib extensions must be specified for the VS on mac / web api combo but are left blank in the WkHtmlToXBindings.cs file (line 11). The hack-fix that ended up working was to leave the 64-bit files in the root and create a post-build event that copied the 32-bit files to the output directory when doing a production build. Here is an example:
Now I'm able to run locally and in my hosted environment, although it was a painful to get there. I'm sure there are more elegant solutions but too much time has been spent getting it to work. I hope this helps someone else. |
The target platform is replaced by X64 or X86. |
@rokeyyan If I understand your question correctly, in my setup for the Build Configuration "Release" for the Platform "Any CPU", the post-build action copies the 32-bit versions to the root. The ${TargetDir} looks something like this:
I hope this helps! |
Recently I faced the same problem. Maybe this is a really stupid question, but is there any reason why the libwkhtmltox dll and other binaries are not packaged together in the DinkToPdf nuget package? |
Doesnt work on mac here either, same error... cant we package the DLL in the library, this is a farce. |
frustrating to read through all the comments with no resolution - there's obviously an issue with core 2 loading external dll's |
I am getting the below error, Unable to load DLL 'libwkhtmltox'. Given below are the configurations Application is working fine with development server in IIS express. but while deployed in IIS(windows 2012 R2 - .net Core 2.0), application 1)libwkhtmltox(12.4) is copied in the root directory. Please support. |
It did in my case, in case anybody is interested :) Thanks so much! |
issue was resolved after installing MS visual C++ 2015 redistributable package in the server. Thanks a lot for the support |
It's work for me in this case |
I tried this and its working locally fine for me but when I'm trying to publish in azure I'm getting the following error and the whole application is failing 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) |
its very pain to use this library. I'm getting following exception when I'm deploying with Azure service fabric. So my deployment gets failed when I tried to load unmanaged library. I have tried all the solutions mentioned above. Can anyone please help me out, I have waste lot of time to get it work. Description: The process was terminated due to an unhandled exception. |
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: #18. Hopefully this saves someone time from trying the myriad solutions listed in this thread. |
hi thanks for the help thnaks |
download this on server, where you try to use libwkhtmltox.dll |
why is this issue closed? I can only see some random person's workaround / hack. this is pretty sloppy, having to load an unmanaged DLL. |
I'm guessing more people are running into the issue of not having the C++ libs loaded as mentioned by @MarcusBullock . We had this happen and the error is pretty misleading. It worked fine locally and on our development env, but promoting to pre-prod we hit this error. |
@dgwaldo @MarcusBullock you can use |
This solves the problem about "pdftools.cs not found." |
I am running the code in Lambda with .net core 3.1 runtime and getting the following error
Verified that the files libwkhtmltox.dll and libwkhtmltox.so are part of the final lambda package. Tried switching from DinkToPdf to RndUsr0.DinkToPdf as mentioned above and it still didn't work, giving the exact same error. Also tried loading the unmanaged dll using the suggested workaround, everything works perfectly on local, test cases pass. As soon as we package and push to lambda, it fails at runtime. // .csproj reference used
<None Update="libwkhtmltox.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="libwkhtmltox.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
// Assembly load code reference used
var context = new AssemblyLoader();
context.LoadUnmanagedLibrary(Directory.GetCurrentDirectory() + "/libwkhtmltox.dll");
_dinkToPdfConverter = new SynchronizedConverter(new PdfTools()); This library is so frustrating to wrap my head around. Even after reading so many comments at multiple places, still doesn't have a clear solution to fix it. |
@ahjashish Did you find any solution for this issue? |
Thanks it worked |
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: tuespetre/TuesPechkin#57). Is it possible to do something similar in DinkToPdf?
The text was updated successfully, but these errors were encountered: