Skip to content
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

BadImageFormatException #18

Open
redserpent7 opened this issue May 14, 2015 · 7 comments
Open

BadImageFormatException #18

redserpent7 opened this issue May 14, 2015 · 7 comments

Comments

@redserpent7
Copy link

Hi,

I downloaded ghostscriptsharp from NuGet and whenever I call: GhostscriptWrapper.GenerateOutput(pdfPath, pagePath, settings);

It gives me a BadImageFormatException "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"

I tried building my project with AnyCPU, 32 and 64 bit architecture but always getting the same exception.

@MichaelAlt
Copy link

@redserpent7 Had the same Problem, are you using 64 bit architecture? I had to copy the gsdll64.dll from my GhostScript installation folder and copy it to the Release folder of my Project and rename it to gsdll32.dll. It worked fine from that point on.

I guess that Ghostscriptsharp is not realy supporting 64 bit architecture because the gsdll64.dll is missing in the nuget package.

@dylanvdmerwe
Copy link

Nice work around that does the trick!

@jsacker
Copy link

jsacker commented May 16, 2018

To MichaelAlt: You saved my bacon man! I would never have figured out that renaming a dll would fix the issues. Thanks.

@johanpretoriusza
Copy link

@MichaelAlt, thank you. Solved our problem as well.

@jahav
Copy link

jahav commented Mar 10, 2020

I used dotPeek to see what is going on, because there was a merge request to support 64 bit that should work. The published nuget package 1.3.1.4 only looks for gsdll32.dll and calls its methods.

So basically the latest nuget package (from 6/2/2014) doesn't contain it the support for 64bit that was supplied in a PR and merged in f4fa63b (Oct 15, 2013). Instead, it uses some other obsolete version of the project.

WTF?

Anyway, thanks @MichaelAlt, your help is appreciated many years later.

@Grid-Code
Copy link

@MichaelAlt, thank you. Solved my problem as well - This is a Brilliant for any Future issues regarding 32 bit & 64 Bit

@jay8anks
Copy link

jay8anks commented Jun 17, 2021

Just for fyi, ghostscriptsharp has been used for several years on a shared host. Moved to a VPS and got the BadImageFormatException.

I have tried

  1. Set IIS to allow 32-bit code = true. Recycled the app pool.
  2. Renaming 64bit ghostscript dll to the same name as the 32bit dll name and copying to bin folder on the VPS using 32 bit ghostscriptsharp.dll.
  3. Downloading ghostscriptshart and building it with CPU set to x64 and x86. Uploaded both versions to the VPS at different times just for testing.

So far, nothing works. Later on tonight, I will stop and start the website and see if that does anything, as it looks like just changing the app pool to allow 32 bit dlls should have fixed it.

My local pc is Windows 10, x64 and it works fine locally, out of Visual Studio. The new VPS is Windows Server 2019 x64.

Very frustrating. I actually tested a lot of stuff before moving to the new server, but I missed this issue.

-=-=-=

Update. After stopping and restarting the website in IIS, PDF thumbnails are working again. I'm going to assume the fix was setting the app pool to allow 32 bit to run, because I have the 32 bit versions of ghostscriptsharp and ghostscript.dll on the VPS and they are working.

So, IIS > application pool > {website} and right click > Advanced Settings > Enable 32-bit Applications = True.

Recycle the app pool AND stop and start the website.

-=-=-=

Update. The VPS had a similar site with an almost identical structure. I was able to confirm that just setting the IIS application pool to allow 32 bit applications and recycling the app pool/stop starting the website will make everything go back to work. Stopping and starting the website seems to be a big factor in this, so don't skip it.

Of course, not everyone has access to IIS to do that. It would be nice if the 64 bit versions would actually work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants