When running the code on Mono on Linux, calling .Open(...) on the GhostscriptRasterizer fails with an exception. It appears that the code is attempting to find the installation location of Ghostscript from the Registry (which in case of Linux installations is the Mono registry in e.g. /etc/mono/registry) but totally ignores that a valid Ghostscript library might already be in the path.
Unhandled Exception:
System.AggregateException: One or more errors occurred. ---> Ghostscript.NET.GhostscriptLibraryNotInstalledException: This managed library is running under 64-bit process and requires 64-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html
at Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion (Ghostscript.NET.GhostscriptLicense licenseType, Ghostscript.NET.GhostscriptLicense licensePriority) [0x00068] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open (System.IO.Stream stream) [0x0000e] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at PdfExtract.Program.ExtractImages (System.IO.Stream stream, System.IO.DirectoryInfo outputPath, System.Int32 dpi, System.Int64 quality) [0x00072] in <1687eef90b70415191e0dd63b40d465f>:0
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <204f770036d441bb8dfd3daba3550e83>:0
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in <204f770036d441bb8dfd3daba3550e83>:0
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x0000f] in <204f770036d441bb8dfd3daba3550e83>:0
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication+<>c__DisplayClass79_0.<OnExecute>b__0 () [0x0000b] in <af5004465019421ab8103642fc8570cf>:0
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x0035b] in <af5004465019421ab8103642fc8570cf>:0
at Everybag.PdfExtract.Program.Main (System.String[] args) [0x0010d] in <1687eef90b70415191e0dd63b40d465f>:0
---> (Inner Exception #0) Ghostscript.NET.GhostscriptLibraryNotInstalledException: This managed library is running under 64-bit process and requires 64-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html
at Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion (Ghostscript.NET.GhostscriptLicense licenseType, Ghostscript.NET.GhostscriptLicense licensePriority) [0x00068] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open (System.IO.Stream stream) [0x0000e] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at PdfExtract.Program.ExtractImages (System.IO.Stream stream, System.IO.DirectoryInfo outputPath, System.Int32 dpi, System.Int64 quality) [0x00072] in <1687eef90b70415191e0dd63b40d465f>:0
I was trying to force it to use my system version by providing a GhostscriptVersionInfo to as .Open(..., gvi) as
var gvi = new GhostscriptVersionInfo("/usr/lib/x86_64-linux-gnu/libgs.so.9");
and
var gvi = new GhostscriptVersionInfo(new Version(9, 18), "/usr/lib/x86_64-linux-gnu/libgs.so.9", "/usr/lib/x86_64-linux-gnu/libgs.so.9", GhostscriptLicense.GPL);
but that led to another (misleading) exception:
System.AggregateException: One or more errors occurred. ---> System.BadImageFormatException: You are using native Ghostscript library (gsdll32.dll) compiled for 32bit systems in a 64bit process. You need to use gsdll64.dll. 64bit native Ghostscript library can be downloaded from http://www.ghostscript.com/download/gsdnld.html
at Ghostscript.NET.GhostscriptLibrary.ThrowIncompatibileNativeGhostscriptLibraryException () [0x0000e] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.GhostscriptLibrary..ctor (Ghostscript.NET.GhostscriptVersionInfo version, System.Boolean fromMemory) [0x0004c] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Interpreter.GhostscriptInterpreter..ctor (Ghostscript.NET.GhostscriptVersionInfo version, System.Boolean fromMemory) [0x0002a] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Viewer.GhostscriptViewer.Open (System.String path, Ghostscript.NET.GhostscriptVersionInfo versionInfo, System.Boolean dllFromMemory) [0x0002f] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Viewer.GhostscriptViewer.Open (System.IO.Stream stream, Ghostscript.NET.GhostscriptVersionInfo versionInfo, System.Boolean dllFromMemory) [0x0002f] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open (System.IO.Stream stream, Ghostscript.NET.GhostscriptVersionInfo versionInfo, System.Boolean dllFromMemory) [0x00024] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at PdfExtract.Program.ExtractImages (System.IO.Stream stream, System.IO.DirectoryInfo outputPath, System.Int32 dpi, System.Int64 quality) [0x0008d] in /home/mmayer/dev/everybag/Everybag.PdfExtract/src/Everybag.PdfExtract/Program.cs:219
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <204f770036d441bb8dfd3daba3550e83>:0
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in <204f770036d441bb8dfd3daba3550e83>:0
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x0000f] in <204f770036d441bb8dfd3daba3550e83>:0
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication+<>c__DisplayClass79_0.<OnExecute>b__0 () [0x0000b] in <af5004465019421ab8103642fc8570cf>:0
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x0035b] in <af5004465019421ab8103642fc8570cf>:0
at PdfExtract.Program.Main (System.String[] args) [0x0010d] in /home/mmayer/dev/everybag/Everybag.PdfExtract/src/Everybag.PdfExtract/Program.cs:42
---> (Inner Exception #0) System.BadImageFormatException: You are using native Ghostscript library (gsdll32.dll) compiled for 32bit systems in a 64bit process. You need to use gsdll64.dll. 64bit native Ghostscript library can be downloaded from http://www.ghostscript.com/download/gsdnld.html
at Ghostscript.NET.GhostscriptLibrary.ThrowIncompatibileNativeGhostscriptLibraryException () [0x0000e] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.GhostscriptLibrary..ctor (Ghostscript.NET.GhostscriptVersionInfo version, System.Boolean fromMemory) [0x0004c] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Interpreter.GhostscriptInterpreter..ctor (Ghostscript.NET.GhostscriptVersionInfo version, System.Boolean fromMemory) [0x0002a] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Viewer.GhostscriptViewer.Open (System.String path, Ghostscript.NET.GhostscriptVersionInfo versionInfo, System.Boolean dllFromMemory) [0x0002f] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Viewer.GhostscriptViewer.Open (System.IO.Stream stream, Ghostscript.NET.GhostscriptVersionInfo versionInfo, System.Boolean dllFromMemory) [0x0002f] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open (System.IO.Stream stream, Ghostscript.NET.GhostscriptVersionInfo versionInfo, System.Boolean dllFromMemory) [0x00024] in <5f6fd62cf1d54aefb818afa45c4a7251>:0
at PdfExtract.Program.ExtractImages (System.IO.Stream stream, System.IO.DirectoryInfo outputPath, System.Int32 dpi, System.Int64 quality) [0x0008d] in /home/mmayer/dev/everybag/Everybag.PdfExtract/src/Everybag.PdfExtract/Program.cs:219
The file is a 64bit shared library indeed, but the assumptions in NativeLibraryHelper make it believe it's not, because it's not an NT DLL.
When running the code on Mono on Linux, calling
.Open(...)
on theGhostscriptRasterizer
fails with an exception. It appears that the code is attempting to find the installation location of Ghostscript from the Registry (which in case of Linux installations is the Mono registry in e.g./etc/mono/registry
) but totally ignores that a valid Ghostscript library might already be in the path.I was trying to force it to use my system version by providing a
GhostscriptVersionInfo
to as.Open(..., gvi)
asand
but that led to another (misleading) exception:
The file is a 64bit shared library indeed, but the assumptions in
NativeLibraryHelper
make it believe it's not, because it's not an NT DLL.