2
votes

PDF converting fails while running test on CI. I'm using GhostscriptsSharp library for converting.

I'm not facing this issue while running my test locally, PDF-file is converted to images correctly.

I've been searching the internet for a solution but so far every thing I've found hasn't helped me find a solution.

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 GhostscriptSharp.GhostscriptWrapper.CreateAPIInstance(IntPtr& pinstance, IntPtr caller_handle) at GhostscriptSharp.GhostscriptWrapper.CallAPI(String[] args) at GhostscriptSharp.GhostscriptWrapper.GeneratePageThumbs(String inputPath, String outputPath, Int32 firstPage, Int32 lastPage, Int32 width, Int32 height) at Framework.Utils.FileUtils.ConvertPdfToImages(String pdfPath, String imagesPath, Int32 pageCount) in c:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\Framework\Utils\FileUtils.cs:line 90 at StepDefinitions.General.Search.SearchTableSteps.ThenImagesAreCorrectInDownloadedDocumentFromSearchGrid(Table table) in c:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\StepDefinitions\General\Search\SearchTableSteps.cs:line 282 at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep() at Features.Clerk.Version_2.Clerk_QuickDocFeature.ScenarioCleanup() in c:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\Features\Clerk\version_2\ClerkQuickDoc.feature.cs:line 0 at Features.Clerk.Version_2.Clerk_QuickDocFeature.Clerk_DownloadRedactedDocument() in c:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\Features\Clerk\version_2\ClerkQuickDoc.feature:line 28 at TechTalk.SpecRun.Framework.TaskExecutors.StaticOrInstanceMethodExecutor.ExecuteInternal(ITestThreadExecutionContext testThreadExecutionContext) in c:\TeamCity\buildAgent\work\1ace6ed01d0a43bb\TechTalk.SpecRun.Framework.Interfaces\TaskExecutors\StaticOrInstanceMethodExecutor.cs:line 40 at TechTalk.SpecRun.Framework.TestAssemblyExecutor.ExecuteTestNodeTask(TestNode testNode, ITaskExecutor task, TraceEventType eventType) in c:\TeamCity\buildAgent\work\1ace6ed01d0a43bb\TechTalk.SpecRun.Framework.Executor\TestAssemblyExecutor.cs:line 215

4
Without the relevant steps/code responsible for the error message, it will be difficult to help you with your problem.Nahuel Ianni
There is a 64 bit version of ghostscriptsharp now. However, I couldn't get it to work at all. As others have noted, if you have IIS available and don't mind allowing 32 bit applications to run, this is the fix: IIS > application pool > {website} and right click > Advanced Settings > Enable 32-bit Applications = True. Recycle the app pool AND stop and restart the website.user1544428

4 Answers

4
votes

The 'incorrect format' error usually occurs when attempting to load a non-.NET assembly (e.g. a native code DLL) as if it were a .NET assembly, or a binary that was compiled for a different platform (e.g. 32 bit vs. 64 bit). Use a tool such as ILSpy (for managed assemblies) or Dependency Walker (for native DLLs) to verify that the binary's properties match those of the process. Since it looks like a 3rd party assembly (GhostscriptSharp) is attempting the load, it may be necessary to reflect that assembly to determine which file the error is about.

3
votes

If exception is thrown with message "An attempt was made to load a program with an incorrect format", this is likely due to the 32-bit file gsdll32.dll running on a 64-bit server. In , you must set "Enable 32-Bit Applications" to True for the Application Pool in which the application runs. Recycle the App Pool after making this change.

Derived from this answer.

0
votes

I've solved the same problem in my project in Visual Studio 2013 by checking the option Project->Properties->Build Platform target: Prefer 32-bit (if Platform target is set to Any CPU)

0
votes

Under the team city build step for xunit there is, under advanced options, a .NET Runtime, with a dropdown for platform (which is normally hidden). This defaults to Any CPU/MSIL which runs xunit.console.exe which is 64 bit. If you change it to x86 it'll use xunit.console.x86.exe which will succeed.