This project is read-only.

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

May 7, 2014 at 12:01 PM
Edited May 7, 2014 at 12:05 PM
Hi, my code looks like this:
MemoryStream ms = new MemoryStream(bytes);
if (_rasterizer != null)
_rasterizer = new GhostscriptRasterizer();
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
  Message=Object reference not set to an instance of an object.
       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)
May 7, 2014 at 8:04 PM
Edited May 7, 2014 at 8:05 PM

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 and attach Ghostscript.NET project instead of dll. This will give you more clear exception.

May 8, 2014 at 9:21 AM
Edited May 8, 2014 at 9:21 AM
i'm using the newest version of
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.

May 8, 2014 at 10: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

May 8, 2014 at 10: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.

May 8, 2014 at 11: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:

May 8, 2014 at 11:25 AM
Edited May 8, 2014 at 11: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 :)

May 8, 2014 at 12:52 PM
Hi Anders,

Great, no worries.