Hi Josip,
I've had a go at debugging the code, and you were right - there was an issue with DynamicNativeLibrary, but it looks like the issue isn't Server 2012 R2, but rather the memory size difference.
The code on the server was failing at this point:
If you think this is the right solution, would you be able to incorporate this into the next release please?
Many thanks,
Antony
I've had a go at debugging the code, and you were right - there was an issue with DynamicNativeLibrary, but it looks like the issue isn't Server 2012 R2, but rather the memory size difference.
The code on the server was failing at this point:
GhostsciptInterpreter.Initialize()
int rc_ins = _gs.gsapi_new_instance(out _gs_instance, IntPtr.Zero);
_gs.gsapi_new_instance was set to null, so I had a look at where it gets initialized:GhostscriptLibrary.Initialize()
this.gsapi_new_instance = _library.GetDelegateForFunction("gsapi_new_instance", typeof(gsapi_new_instance)) as gsapi_new_instance;
All the functions in the library were returning as null. Looking at GetDelegateForFunction in DynamicNativeLibrary, it uses the following method to set the addresses:DynamicNativeLibrary.GetProcAddress(procName)
...
// search function name in list of exported names
nameRef = (uint*)(codeBase + exports->AddressOfNames);
ordinal = (ushort*)(codeBase + exports->AddressOfNameOrdinals);
for (i = 0; i < exports->NumberOfNames; i++, nameRef++, ordinal++)
{
IntPtr procNameHandle = (IntPtr)((byte*)((uint)codeBase + *nameRef));
string testProcName = Marshal.PtrToStringAnsi(procNameHandle);
if (testProcName == procName)
{
idx = *ordinal;
break;
}
}
nameRef / ordinal were pointing to the right place, but the procNameHandle was always pointing to an inaccessible memory block. (uint)codeBase was not evaluating correctly, so I changed it to IntPtr procNameHandle = (IntPtr)((byte*)((UInt64)codeBase + *nameRef));
And it works! So it looks like the codeBase pointer was being truncated.If you think this is the right solution, would you be able to incorporate this into the next release please?
Many thanks,
Antony