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

There are 4 answers

0
Kai van Lopik On

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.

1
JustinStolle On

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
Goran Kuručev On

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
mr.gaffo On

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.