Ghostscript weird lock on dll (An error occured wh

2019-07-25 02:43发布

问题:

I have a C#/MVC website for uploading PDFs and when multiple browser instances try to upload at the same time, using Ghostscript.Net v 1.2.1, I get the following error:

Ghostscript.NET.GhostscriptAPICallException: An error occured when call to 'gsapi_new_instance' is made: -100 at Ghostscript.NET.Interpreter.GhostscriptInterpreter.Initialize() at Ghostscript.NET.Interpreter.GhostscriptInterpreter..ctor(GhostscriptVersionInfo version, Boolean fromMemory) at Ghostscript.NET.Viewer.GhostscriptViewer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) at Ghostscript.NET.Viewer.GhostscriptViewer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory)`

It breaks here:

private Ghostscript.NET.GhostscriptVersionInfo _version = Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion(Ghostscript.NET.GhostscriptLicense.GPL | Ghostscript.NET.GhostscriptLicense.AFPL, Ghostscript.NET.GhostscriptLicense.GPL); 

using (var raster = new GhostscriptRasterizer())
{               
    raster.Open(fileStream, _version, false);
}

on the Open. This code is called from within a function called by a async Task<ActionResult>. I wonder if the async is somehow breaking it. On the GhostScript site, the closest related answer I could find is to make sure I Close()/Dispose() prior instances -- however this is not my issue as the problem is concomitant instances in different browser sessions calling down into the same .dll (which does have Everyone permissions in IIS).

There is no static variables in reference to any of this, and it happens off an originating HttpPost.

回答1:

As per https://github.com/jhabjan/Ghostscript.NET/issues/10 , you likely need to change:

raster.Open(fileStream, _version, false);

to:

raster.Open(fileStream, _version, true);