This project is read-only.

Additional information: An error occured when call to 'gsapi_new_instance' is made: -100

Jan 13, 2014 at 2:58 PM
Edited Jan 13, 2014 at 2:59 PM
I am getting the error I placed in the subject line

here it is again:
Additional information: An error occured when call to 'gsapi_new_instance' is made: -100


My Code:
 Dim desired_x_dpi As Integer = 96
Dim desired_y_dpi As Integer = 96

Dim inputPdfPath As String = objDownload.FilePath

objLastInstalledVersion = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL, GhostscriptLicense.GPL)

objRasterizer = New GhostscriptRasterizer()

objRasterizer.Open(inputPdfPath, objLastInstalledVersion, False)


Dim img As Image = objRasterizer.GetPage(desired_x_dpi, desired_y_dpi, 1)
Dim ms As New MemoryStream()
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png)

imgPreview.Src = "data:image/png;base64," & Convert.ToBase64String(ms.ToArray)
GetLastInstalledVersion works and returns my 32bit version of gs.

the error is on this line:
objRasterizer.Open(inputPdfPath, objLastInstalledVersion, False)
Jan 13, 2014 at 4:21 PM
Hi,

Can you please check if you are running your application in 32 or 64 bit mode? What is the platform target selected in your project properties?

Cheers,
Josip
Jan 13, 2014 at 4:50 PM
I am running in 32bit mode.

IIS 7

Ghostscript 32bit 9.10

I am using VS2013--how do I find the target?

Thanks, Josip!

Jimmy
Jan 13, 2014 at 5:11 PM
Can you try to give your IIS user admin rights or allow read permission to "C:\Program Files\gs\gs9.10\bin\gsdll32.dll" to your IIS user?
Jan 13, 2014 at 5:18 PM
IIS User now has full control on that folder.
Well, it is actually "C:\Program Files (x86)\gs\gs9.10\bin" since it is the 32 bit version

Still getting same error

More information:

the outer error I am getting is

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 74: Dim img As Image = objRasterizer.GetPage(desired_x_dpi, desired_y_dpi, 1)
Line 75: Dim ms As New MemoryStream()
Line 76: img.Save(ms, System.Drawing.Imaging.ImageFormat.Png) <<<<<<<<<<<<<Highlighted
Line 77:

Line 78: imgPreview.Src = "data:image/png;base64," & Convert.ToBase64String(ms.ToArray)

I think this error comes from the error I listed above which only appears in debug mode.
Jan 13, 2014 at 5:20 PM
Ok, now I am getting this error



An error occured when call to 'gsapi_new_instance' is made: -100
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Ghostscript.NET.GhostscriptAPICallException: An error occured when call to 'gsapi_new_instance' is made: -100

Source Error:


Line 69: objRasterizer = New GhostscriptRasterizer()
Line 70:
Line 71: objRasterizer.Open(inputPdfPath, objLastInstalledVersion, False)
Line 72:
Line 73:

Source File: C:\projects\jandj\CorpPortal\Website\Controls\General\PDFPreview.ascx.vb Line: 71
Stack Trace:


[GhostscriptAPICallException: An error occured when call to 'gsapi_new_instance' is made: -100]
Ghostscript.NET.Interpreter.GhostscriptInterpreter.Initialize() +98
Ghostscript.NET.Interpreter.GhostscriptInterpreter..ctor(GhostscriptVersionInfo version, Boolean fromMemory) +64
Ghostscript.NET.Viewer.GhostscriptViewer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) +75
Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) +57
Controls_General_PDFPreview.Page_Load(Object sender, EventArgs e) in C:\projects\jandj\CorpPortal\Website\Controls\General\PDFPreview.ascx.vb:71
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Control.AddedControl(Control control, Int32 index) +260
System.Web.UI.ControlCollection.Add(Control child) +86
MMS_SMARTTrip_ExpensePRO_ExpenseEdit.rptImages_ItemDataBound(Object sender, RepeaterItemEventArgs e) in C:\projects\jandj\CorpPortal\Website\MMS\SmartTrip\ExpensePRO\ExpenseEdit.aspx.vb:251
System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e) +111
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +138
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +9765387
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +61
System.Web.UI.WebControls.Repeater.DataBind() +105
System.Web.UI.WebControls.Repeater.EnsureDataBound() +49
System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +15
System.Web.UI.Control.PreRenderRecursiveInternal() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
Jan 13, 2014 at 5:31 PM
Edited Jan 13, 2014 at 6:34 PM
Ok, the "C:\Program Files (x86)" tells me that you are running this on the 64 bit machine. Do you have 64 bit version of the Ghostscript installed ? If no, can you try to install it as there is a chance that your web application is running as 64 bit process under the IIS when it's deployed.
Jan 13, 2014 at 7:40 PM
I added the 63bit and removed the 32bit and got this error.

__This managed library is running under 32-bit process and requires 32-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html__

I am going to put the 32bit back.
Jan 15, 2014 at 9:01 PM
Edited Jan 15, 2014 at 9:01 PM
The initial error "gsapi_new_instance": -100 says that Ghostscript instance could not be created.

If you want and you can give me access to your machine via TeamViewer I can debug it directly on your machine, that would save us both a lot of time. You can let me know via habjan@gmail.com.

Cheers,
Josip
Feb 23, 2014 at 1:32 PM
I had the same issue in a winform app.
The cause was I was reusing a single GhostscriptViewer instance to open multiple documents. Even creating a new instance for each pdf was throwing the exception when the garbage collector didn't had enough time to dispose the unmanaged resources. I ended up by creating a private member variable to hold the GhostscriptViewer and before opening a new pdf I disposed the viewer if it was not null:
private GhostscriptViewer gsViewer;
// ...

 if(this.gsViewer != null)
    this.gsViewer.Dispose();
this.gsViewer = new GhostscriptViewer();
poz
Jun 6, 2014 at 9:42 PM
We just had the same issue and GambitRicky's fix worked for us.

We are using the GhostscriptRasterizer (which has a viewer in it), and successive calls threw that error. Disposing the rasterizer on completion resolved it.
Jun 18, 2014 at 11:03 AM
Hi,

Thanks for reporting this, I will try to reproduce this problem and fix it for the next release.

Cheers,
Josip
Aug 5, 2014 at 11:04 PM
Edited Aug 6, 2014 at 1:23 PM
Is there any update on the "An error occured when call to 'gsapi_new_instance' is made: -100" exception with GhostscriptRasterizer?

I have the following method in a Web service with the last statement (rasterizer.Open(ms);) throwing the abovementioned exception:
public void Resterize(byte[] buffer)
{
    MemoryStream ms = new MemoryStream(buffer);
    lock("GhostscriptRasterizer")
    {
       GhostscriptRasterizer rasterizer = new GhostscriptRasterizer();
       rasterizer.Open(ms);
       ....................................................
    }
    ....................................................
    ....................................................
}
Occasionally the same statement would throw: "An error occured when call to 'gsapi_init_with_args' is made: -15" exception.

I am using Ghostscript.Net version 1.1.9.0.
Aug 6, 2014 at 1:59 PM
I also tried to replace the offending statement with the more I also tried to replace the offending statement with the more explicit one, but consistently getting -15 error now.
rasterizer.Open(ms, GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL,GhostscriptLicense.GPL), true);