DinkToPdf
DinkToPdf copied to clipboard
System.BadImageFormatException: An attempt was made to load a program with an incorrect format.
I have asp.net core 2.1 project which I use 64 bit libwkhtmltox.dll
. Locally all works fine either while debugging or hosting on local iis. However when I host it on server which is win 64 bit OS, exception is thrown as like;
System.AggregateException: One or more errors occurred. (An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)) ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
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.Tasks.Task.<>c.<.cctor>b__278_1(Object obj)
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.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
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)
deps.json configuration is as follows
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v2.1",
"signature": "17c0d97ba89af48f20c96c6f42ea9f22e1c7de55"
},
"compilationOptions": {
"defines": [
"TRACE",
"RELEASE",
"NETCOREAPP",
"NETCOREAPP2_1"
],
"languageVersion": "",
"platform": "AnyCPU",
"allowUnsafe": false,
"warningsAsErrors": false,
"optimize": true,
"keyFile": "",
"emitEntryPoint": true,
"xmlDoc": false,
"debugType": "portable"
},
"targets": {
".NETCoreApp,Version=v2.1": {
"KatefWeb/1.0.0": {
"dependencies": {
"Dapper": "1.50.5",
"Dapper.Contrib": "1.50.5",
"DinkToPdf": "1.0.8",
"Katef.Core": "1.0.0",
"Microsoft.AspNetCore.App": "2.1.1",
"Microsoft.NETCore.App": "2.1.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Design": "2.1.1",
"Serilog": "2.8.0",
"Serilog.AspNetCore": "2.1.1",
"Serilog.Settings.Configuration": "3.0.1",
"Serilog.Sinks.MSSqlServer": "5.1.2",
"System.Drawing.Common": "4.5.1"
},
Publishing with options Portable
and Framework-Dependent
.
As I know this exception is a 64 bit/ 32 bit conflict in general, I replaced the dll on server with a 32 bit one and exception gone, but I don't know why.
@fabercs I faced same Issue and after replacing all the dll on server with 32 bit it worked for me also.
Thank you :) !
As I know this exception is a 64 bit/ 32 bit conflict in general, I replaced the dll on server with a 32 bit one and exception gone, but I don't know why.
x2
@Ksantacr from where did you get the 32 bit one? TY
@Ksantacr from where did you get the 32 bit one? TY
From here https://github.com/rdvojmoc/DinkToPdf/tree/master/v0.12.4/32%20bit
Just wanted to check the source... I got it from the same place and I can't make it work, I'm having this error no matter the version. I'm using Core 3.1. Any help would be really much appreciated!
Just wanted to check the source... I got it from the same place and I can't make it work, I'm having this error no matter the version. I'm using Core 3.1. Any help would be really much appreciated!
Full source code https://github.com/rdvojmoc/DinkToPdf/tree/master/src/DinkToPdf I solved this issue in IIS .net core app 3.1
Could you share an example project? It does not work for me at all. I have even created an independent issue. No matter what I try it just doesn't work and the error is the same.
Could you share an example project? It does not work for me at all. I have even created an independent issue. No matter what I try it just doesn't work and the error is the same.
Same here using core 3.1 ..it works fine locally but doesn't work on iis
Hey guys does anyone have any updates on this? I'm experiencing the same issue. On my local the 64bit library works, however in Azure only the 32bit works. Experiencing the same error as above:
An attempt was made to load a program with an incorrect format.
Does anyone have any thoughts on a way to include both libraries and have the function work out which it requires? Cheers!
@jimmytricks you can change azure to be 64bit -
Thanks @IeuanWalker - haven't tried this yet, but looks like it'll resolve it, cheers
Hi, I have the same issue however my issue is that I can't even make it work locally. I tried replacing 32bit and 64bit but still having this issue. I am using it on my .NET 5 Project and Visual Studio 2019 Community on windows 10 64 bit environment
I resolved this as below [appreciate everyone's answer which led me to the solution.]
- Created Azure Function App [Windows, .Net 6]
- Deployed Azure Function [Used 32bit libwkhtmltox.dll]
- Got the 'above noted' error.
- Tried replacing 64bit "libwkhtmltox.dll' to 32 bit
- Still the same error was there.
- Then Changed Azure Function app runtime from 32bit to 64bit.
- Placed 64bit libwkhtmltox.dll
- Did refresh
- Tested - Worked fine.
Hope this helps!
Hello I tried updating Azure to 64 bit but still giving the error
System.AggregateException: One or more errors occurred. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
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.Task1.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 48
at DinkToPdf.SynchronizedConverter.Convert(IDocument document) in C:\Users\admin\Documents\DinkToPdf\src\DinkToPdf\SynchronizedConverter.cs:line 27
at PdfService.GeneratePdf(String header, String htmlContent) in D:\Yash\Transom Corporation\Scentia Selection Program\selection-program\api\WebApi\Helpers\PDF\PdfService.cs:line 19
at WebApi.Controllers.PdfController.Get(String id, String type, Nullable1 dimensions, Nullable
1 electrical, String funds, Nullable1 multiplier, String delivery, String terms) in D:\Yash\Transom Corporation\Scentia Selection Program\selection-program\api\WebApi\Controllers\PdfController.cs:line 266 ---> (Inner Exception #0) System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) 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()<---
Any help on this will be appriciated