Trying to use GemBox PDF to combine files, but we are doing so via Node.js code → Edge-JS module → GemBox. When I run my script, it says that GemBox throws the following error:
Message: "The type initializer for 'GemBox.Pdf.PdfDocument' threw an exception.",
Data: {},
InnerException: Error: Could not load file or assembly 'System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))
We are using the latest version of GemBox.PDF (2025.5.103), and the directory where the DLL is contains everything in the GemBox Software\GemBox.Pdf\Bin\net462 directory when we installed GemBox.
The script being run is as follows:
// to join files
#r "C:/libraries/gembox/GemBox.Pdf.dll"
using System;
using System.Runtime;
using GemBox.Pdf;
using System.Threading.Tasks;
//this class need to be name Startup as it used by edge.js
public class Startup
{
//this method need to be named Invoke it starts program
public async Task<object> Invoke(string input)
{
Console.WriteLine(input);
string document = input;
Gembox.Create(input);
return "Converted";
}
//helper class do the conversion
public class Gembox
{
public static void Create(string doc)
{
//need more work to return stream
ComponentInfo.SetLicense("*****");
// List of source file names.
var fileNames = new string[]
{
"C:\temp\temp13232.pdf"
};
using (var document = new PdfDocument())
{
// Merge multiple PDF files into single PDF by loading source documents
// and cloning all their pages to destination document.
foreach (var fileName in fileNames)
using (var source = PdfDocument.Load(fileName))
document.Pages.Kids.AddClone(source.Pages);
document.Save(doc);
}
}
}
}
As a comparison, we are doing a very similar thing with GemBox.Document, however, it is a much older version of GemBox.Document. It runs without issue.
Also, after further testing, it would seem everything works as expected if we use GemBox.Pdf 17.0.1648 or lower. Obviously, we’d like to be able to use the most recent version.
Hi Mario,
Thanks for the quick reply. Appreciate you looking into this for me. I have created a github repo with this issue recreated: GitHub - jeremy-balzer/gembox-pdf-issue
Thanks Mario,
I’m not sure exactly what you mean by “adding references to missing dependencies”. I added all the DLLs listed to the project and the two lines you mentioned to my start.js file, but the error persists.
Anyway, I’m afraid that we’re unable to reproduce your issue, we downloaded your latest version on GitHub (which you updated accordingly) and ran npm install followed by npm run. It ran successfully with this message:
PDFs joined at C:/.../joined.pdf
Can you tell us what version of the .NET Framework you have installed on your machine?
Thanks Mario,
I’m not sure what the difference is. I get the same error as before, even with the 3 references. I have many .NET versions installed, including 4.6.2, 4.8.1, etc.
public async Task<object> Invoke(string input)
{
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
var name = asm.GetName().Name;
if (name == "System.Memory" || name == "System.Runtime.CompilerServices.Unsafe" || name == "GemBox.Pdf")
{
Console.WriteLine(asm.FullName);
Console.WriteLine(asm.Location);
Console.WriteLine(System.Diagnostics.FileVersionInfo.GetVersionInfo(asm.Location));
}
}
var response = new { State = "Success" };
return response;
}
Hi Mario, I may have spoken too soon. Hopefully, this is a quick thing to fix as well.
We use GemBox.Document alongside GemBox.Pdf. After making the updates above, we likewise updated Document to 2025.5.105 (and uninstalled the GemBox.Document Setup as well), but it’s having a problem/conflict with the SkiaSharp.dll in the same folder:
Message: "Unable to load library 'libSkiaSharp'.",
TypeName: '',
Data: {},
InnerException: null,
TargetSite: {},
StackTrace: ' at SkiaSharp.LibraryLoader.LoadLocalLibrary[T](String libraryName)\r\n' +
' at System.Lazy`1.CreateValue()\r\n' +
' at System.Lazy`1.LazyInitValue()\r\n' +
' at SkiaSharp.SkiaApi.sk_graphics_purge_font_cache()\r\n' +
' at \x0E .\x06()\r\n' +
' at Startup.Gembox.Create(String doc)\r\n' +
' at Startup.<Invoke>d__0.MoveNext()',
HelpLink: null,
Source: 'SkiaSharp',
HResult: -2146233052,
name: 'System.DllNotFoundException'
We are converting a DOCX file to a PDF. I have referenced the package:
Ok, that took care of it. I assumed libSkiaSharp was the same or part of SkiaSharp. Thank you again!
Just out of curiosity, in future updates, how would we acquire the dlls like those provided in your zips in this post? Could we just use nuget like we did with the dlls mentioned in the readme?
Yes, you can just use NuGet.
The SkiaSharp and HarfBuzzSharp packages have dependencies to SkiaSharp .NativeAssets.Win32 and HarfBuzzSharp.NativeAssets.Win32, which contain those DLL files I sent you: