【问题标题】:TeamCity: GhostscriptSharp: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)TeamCity:GhostscriptSharp:试图加载格式不正确的程序。 (来自 HRESULT 的异常:0x8007000B)
【发布时间】:2016-05-09 22:35:14
【问题描述】:

在 CI 上运行测试时 PDF 转换失败。我正在使用 GhostscriptsSharp 库进行转换。

我在本地运行测试时没有遇到此问题,PDF 文件已正确转换为图像。

我一直在互联网上寻找解决方案,但到目前为止,我发现的每件事都没有帮助我找到解决方案。

试图加载格式不正确的程序。 (HRESULT 异常:0x8007000B)

System.BadImageFormatException:尝试加载格式不正确的程序。 (来自 HRESULT 的异常:0x8007000B) 在 GhostscriptSharp.GhostscriptWrapper.CreateAPIInstance(IntPtr& pintance, IntPtr caller_handle) 在 GhostscriptSharp.GhostscriptWrapper.CallAPI(String[] args) 在 GhostscriptSharp.GhostscriptWrapper.GeneratePageThumbs(字符串 inputPath,字符串 outputPath,Int32 firstPage,Int32 lastPage,Int32 宽度,Int32 高度) 在 c:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\Framework\Utils\FileUtils.cs:line 90 中的 Framework.Utils.FileUtils.ConvertPdfToImages(String pdfPath, String imagesPath, Int32 pageCount) 在 StepDefinitions.General.Search.SearchTableSteps.ThenImagesAreCorrectInDownloadedDocumentFromSearchGrid(Table table) 在 c:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\StepDefinitions\General\Search\SearchTableSteps.cs:line 282 在 TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding 绑定,IContextManager contextManager,Object[] 参数,ITestTracer testTracer,TimeSpan& 持续时间) 在 TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch 匹配,对象 [] 参数) 在 TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance) 在 TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep() 在 C:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\Features\Clerk\version_2\ClerkQuickDoc.feature.cs:line 0 中的 Features.Clerk.Version_2.Clerk_QuickDocFeature.ScenarioCleanup() 在 Features.Clerk.Version_2.Clerk_QuickDocFeature.Clerk_DownloadRedactedDocument() 在 c:\TeamCity\buildAgent\work\8e7aa88e702dfaf7\Features\Clerk\version_2\ClerkQuickDoc.feature:line 28 在 c:\TeamCity\buildAgent\work\1ace6ed01d0a43bb\TechTalk.SpecRun.Framework.Interfaces\TaskExecutors\StaticOrInstanceMethodExecutor.cs:line 40 中的 TechTalk.SpecRun.Framework.TaskExecutors.StaticOrInstanceMethodExecutor.ExecuteInternal(ITestThreadExecutionContext testThreadExecutionContext) 在 c:\TeamCity\buildAgent\work\1ace6ed01d0a43bb\TechTalk.SpecRun.Framework.Executor\TestAssemblyExecutor.cs:line 215 中的 TechTalk.SpecRun.Framework.TestAssemblyExecutor.ExecuteTestNodeTask(TestNode testNode, ITaskExecutor task, TraceEventType eventType)

【问题讨论】:

  • 如果没有负责错误消息的相关步骤/代码,将很难帮助您解决问题。
  • 现在有 64 位版本的 ghostscriptsharp。但是,我根本无法让它工作。正如其他人所指出的,如果您有可用的 IIS 并且不介意允许 32 位应用程序运行,那么解决方法就是:IIS > 应用程序池 > {website} 并右键单击 > 高级设置 > 启用 32 位应用程序 = True。回收应用程序池并停止并重新启动网站。

标签: c# continuous-integration teamcity badimageformatexception ghostscriptsharp


【解决方案1】:

“格式不正确”错误通常发生在尝试加载非 .NET 程序集(例如本机代码 DLL)时,就好像它是 .NET 程序集或为不同平台编译的二进制文件(例如 32位与 64 位)。使用诸如 ILSpy(用于托管程序集)或 Dependency Walker(用于本机 DLL)之类的工具来验证二进制文件的属性是否与进程的属性匹配。由于看起来第 3 方程序集 (GhostscriptSharp) 正在尝试加载,因此可能需要反映该程序集以确定错误与哪个文件有关。

【讨论】:

    【解决方案2】:

    我在 Visual Studio 2013 的项目中解决了同样的问题,方法是选中 Project->Properties->Build Platform target: Prefer 32-bit (if Platform target is set to Any CPU)

    【讨论】:

      【解决方案3】:

      在 xunit 的团队城市构建步骤下,在高级选项下有一个 .NET 运行时,带有一个平台下拉菜单(通常是隐藏的)。这默认为运行 64 位 xunit.console.exe 的任何 CPU/MSIL。如果您将其更改为 x86,它将使用 xunit.console.x86.exe 会成功。

      【讨论】:

        【解决方案4】:

        如果抛出异常并显示消息“尝试加载格式不正确的程序”,这可能是由于 32 位文件 gsdll32.dll 在 64 位服务器上运行。在 中,必须将运行应用程序的应用程序池的“启用 32 位应用程序”设置为 True。进行此更改后回收应用程序池。

        源自this answer

        【讨论】:

        • 我遇到了这个问题。网站很忙,所以我不想停下来启动它。但是,仅在更改后回收应用程序池不起作用。在 32 位 ghostscriptsharp 开始工作之前,我不得不停止该站点并重新启动它。 IIS > 应用程序池 > {website} 并右键单击 > 高级设置 > 启用 32 位应用程序 = True。
        猜你喜欢
        • 2017-12-31
        • 1970-01-01
        • 2012-04-28
        • 1970-01-01
        • 2011-08-14
        • 1970-01-01
        • 2022-10-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多