_rasterizer.Open(ms) throws System.NullReferenceException in .net 4.5

May 7, 2014 at 11:01 AM
Edited May 7, 2014 at 11:05 AM
Hi, my code looks like this:
MemoryStream ms = new MemoryStream(bytes);
if (_rasterizer != null)
{
   _rasterizer.Dispose();
}
_rasterizer = new GhostscriptRasterizer();
_rasterizer.Open(ms);
Pretty much like the sample code
The error happens at _rasterizer.Open(ms).
This happens only when I'm using .net 4.5.
Both ghostscript and windows is x64.

The whole error :
System.NullReferenceException was unhandled by user code
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Ghostscript.NET
  StackTrace:
       at Ghostscript.NET.Interpreter.GhostscriptInterpreter.InitArgs(String[] args)
       at Ghostscript.NET.Viewer.GhostscriptViewer.Open()
       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(MemoryStream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory)
       at LightSwitchApplication.ApplicationDataService.BøgerSet_Updated(Bøger entity)
       at LightSwitchApplication.ApplicationDataService.DetailsClass.__BøgerSet_Updated(ApplicationDataService d, Bøger e)
       at Microsoft.LightSwitch.Details.Framework.Server.EntitySetEntry`2.Microsoft.LightSwitch.Details.Framework.Server.IEntitySetEntry.InvokeUpdated(IDataService dataService, IEntityObject entity)
       at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.<>c__DisplayClass61.<PerformPostEvent>b__5c(IEntitySetEntry entitySetEntry)
       at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.<>c__DisplayClass43.<CallPrePostUserCode>b__42()
       at Microsoft.LightSwitch.Utilities.Internal.UserCodeHelper.CallUserCode(Type sourceType, String methodName, String instance, String operation, ILoggingContext context, Action action, String additionalText, Func`1 getCompletedMessage, Boolean tryHandleException, Boolean swallowException, Exception& exception)
  InnerException: 
Coordinator
May 7, 2014 at 7:04 PM
Edited May 7, 2014 at 7:05 PM
Hi,

I did test Ghostscript.NET in .NET 4.0. and 4.5., both works for me (x86, x64).

What Ghostscript.NET version do you use?

Try to open MemoryStream this way:
_rasterizer.Open(ms, GhostscriptVersionInfo.GetLastInstalledVersion, false);
Also, you could try to download latest source code from https://github.com/jhabjan/Ghostscript.NET and attach Ghostscript.NET project instead of dll. This will give you more clear exception.

Cheers,
Josip
May 8, 2014 at 8:21 AM
Edited May 8, 2014 at 8:21 AM
Hmm,
i'm using the newest version of Ghostscript.net.
I tried your suggestions, and the error is coming from GhostscriptInterpreter.cs @ line 281.
int rc_enc = _gs.gsapi_set_arg_encoding(_gs_instance, GS_ARG_ENCODING.UTF8);
It seems that _gs.gsapi_set_arg_encoding is null when this is called.

I don't have enough knowledge of Ghostscript to know what this actually means.

Thanks for the helping.

Anders
Coordinator
May 8, 2014 at 9:11 AM
What version of native Ghostscript library do you have installed? If you have older version there is a chance that 'gsapi_set_arg_encoding' is not exposed. Current release is 9.14 which you can download and install from http://www.ghostscript.com/download/gsdnld.html

Cheers,
Josip
Coordinator
May 8, 2014 at 9:18 AM
Hi Anders,

I just found out that 'gsapi_set_arg_encoding' is introduced in Ghostscript 9.10. So, earlier versions are not compatible with Ghostscript.NET.

Cheers,
Josip
Coordinator
May 8, 2014 at 10:23 AM
Hi Anders,

This is fixed for the next release (Ghostscript.NET v.1.1.8).

You can download latest source code which includes this bug fix from GitHub or you can apply changes to your existing source code from this commit: https://github.com/jhabjan/Ghostscript.NET/commit/5239c77f81661785e31660243e996886790fffcb

Cheers,
Josip
May 8, 2014 at 10:25 AM
Edited May 8, 2014 at 10:32 AM
Hi Josip,

I had Ghostscript 9.14 installed.
I uninstalled it and tried the 32 bit version, and for some reason it worked.
Should probably have tried that from the start.

I'm going to test the latest update later.

Thanks for the help, you are doing some amazing work :)

Anders
Coordinator
May 8, 2014 at 11:52 AM
Hi Anders,

Great, no worries.

Cheers,
Josip