GemBox.Pdf - assembly error

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.

Any help would be greatly appreciated. Thank you!

Hi,

Can you please create a small project that reproduces your issue so we can investigate it?

Regards,
Mario

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

Hi,

We were able to make it work by adding references to missing dependencies, you can find the list of them in the README.txt inside the downloaded ZIP:

These are the System.*.dll files needed:

  • System.Buffers.dll
  • System.Memory.dll
  • System.Numerics.Vectors.dll
  • System.ValueTuple.dll
  • System.Runtime.CompilerServices.Unsafe.dll

You can download them from here.

Also, in the “start.js”, add these two lines:

#r "${path.normalize(__dirname + '/System.Runtime.CompilerServices.Unsafe.dll').split('\\').join('/')}"
#r "${path.normalize(__dirname + '/System.Memory.dll').split('\\').join('/')}"

Last, among the dependencies, the DLL files from HarfBuzzSharp, SkiaSharp, and BouncyCastle are missing, so some functionality can be limited.

Regards,
Mario

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.

Hi,

We didn’t have to explicitly write the references, but perhaps for some reason, you will have to.
For example, try this:

// to join files
#r "C:/libraries/gembox/GemBox.Pdf.dll"
#r "C:/libraries/gembox/System.Runtime.CompilerServices.Unsafe.dll"
#r "C:/libraries/gembox/System.Memory.dll"
...

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?

Regards,
Mario

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.

Can you try using this in “start.js”:

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;
}

What do you get as the output?

Here is my output:

C:\Users\User\gembox-pdf-issue-main>node start.js

GemBox.Pdf, Version=2025.5.103.0, Culture=neutral, PublicKeyToken=b1b72c69714d4847
C:\Users\User\gembox-pdf-issue-main\GemBox.Pdf.dll
File:             C:\Users\User\gembox-pdf-issue-main\GemBox.Pdf.dll
InternalName:     GemBox.Pdf.dll
OriginalFilename: GemBox.Pdf.dll
FileVersion:      2025.5.103.462
FileDescription:  GemBox.Pdf 2025.5 for .NET Framework 4.6.2
Product:          GemBox.Pdf 2025.5 for .NET Framework 4.6.2
ProductVersion:   2025.5.103.462+dfb14819e12debfb3c2f52e4b2affcf48ad6cce1
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
C:\Users\User\gembox-pdf-issue-main\System.Runtime.CompilerServices.Unsafe.dll
File:             C:\Users\User\gembox-pdf-issue-main\System.Runtime.CompilerServices.Unsafe.dll
InternalName:     System.Runtime.CompilerServices.Unsafe.dll
OriginalFilename: System.Runtime.CompilerServices.Unsafe.dll
FileVersion:      4.6.28619.01
FileDescription:  System.Runtime.CompilerServices.Unsafe
Product:          Microsoftr .NET Framework
ProductVersion:   4.6.28619.01 @BuiltBy: dlab14-DDVSOWINAGE069 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/7601f4f6225089ffb291dc7d58293c7bbf5c5d4f
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
C:\Users\User\gembox-pdf-issue-main\System.Memory.dll
File:             C:\Users\User\gembox-pdf-issue-main\System.Memory.dll
InternalName:     System.Memory.dll
OriginalFilename: System.Memory.dll
FileVersion:      4.6.31308.01
FileDescription:  System.Memory
Product:          Microsoftr .NET Framework
ProductVersion:   4.6.31308.01 @BuiltBy: cloudtest-841353dfc000000 @Branch: release/2.1-MSRC @SrcCode: https://github.com/dotnet/corefx/tree/32b491939fbd125f304031c35038b1e14b4e3958
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

Here is what I get:

GemBox.Pdf, Version=2025.5.103.0, Culture=neutral, PublicKeyToken=b1b72c69714d4847
C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\GemBox.Pdf\v4.0_2025.5.103.0__b1b72c69714d4847\GemBox.Pdf.dll
File:             C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\GemBox.Pdf\v4.0_2025.5.103.0__b1b72c69714d4847\GemBox.Pdf.dll
InternalName:     GemBox.Pdf.dll
OriginalFilename: GemBox.Pdf.dll
FileVersion:      2025.5.103.462
FileDescription:  GemBox.Pdf 2025.5 for .NET Framework 4.6.2
Product:          GemBox.Pdf 2025.5 for .NET Framework 4.6.2
ProductVersion:   2025.5.103.462+dfb14819e12debfb3c2f52e4b2affcf48ad6cce1
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
C:\DoNotBackup\CrimePad\gembox-demo\System.Runtime.CompilerServices.Unsafe.dll
File:             C:\DoNotBackup\CrimePad\gembox-demo\System.Runtime.CompilerServices.Unsafe.dll
InternalName:     System.Runtime.CompilerServices.Unsafe.dll
OriginalFilename: System.Runtime.CompilerServices.Unsafe.dll
FileVersion:      4.6.28619.01
FileDescription:  System.Runtime.CompilerServices.Unsafe
Product:          Microsoftr .NET Framework
ProductVersion:   4.6.28619.01 @BuiltBy: dlab14-DDVSOWINAGE069 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/7601f4f6225089ffb291dc7d58293c7bbf5c5d4f
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
C:\DoNotBackup\CrimePad\gembox-demo\System.Memory.dll
File:             C:\DoNotBackup\CrimePad\gembox-demo\System.Memory.dll
InternalName:     System.Memory.dll
OriginalFilename: System.Memory.dll
FileVersion:      4.6.31308.01
FileDescription:  System.Memory
Product:          Microsoftr .NET Framework
ProductVersion:   4.6.31308.01 @BuiltBy: cloudtest-841353dfc000000 @Branch: release/2.1-MSRC @SrcCode: https://github.com/dotnet/corefx/tree/32b491939fbd125f304031c35038b1e14b4e3958
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

As you may notice, the GemBox.Pdf.dll file that you’re getting at runtime is not the one you’re expecting to get.

This is the path to the GemBox.Pdf location you have:

C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\GemBox.Pdf\v4.0_2025.5.103.0__b1b72c69714d4847\GemBox.Pdf.dll

It is the one that’s in your GAC, which you probably have installed (GemBox.Pdf Setup) on your machine.

Can you try uninstalling GemBox.Pdf?

1 Like

That was it, Mario! Thank you! I really appreciate you taking the time to solve this for me.

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:

#r "${path.normalize(__dirname + '/GemBox.Document.dll').split('\\').join('/')}"
#r "${path.normalize(__dirname + '/SkiaSharp.dll').split('\\').join('/')}"

The verions/paths seem to be correct:

GemBox.Document, Version=2025.5.105.0, Culture=neutral, PublicKeyToken=b1b72c69714d4847
C:\DoNotBackup\CrimePad\gembox-demo\GemBox.Document.dll
File:             C:\DoNotBackup\CrimePad\gembox-demo\GemBox.Document.dll
InternalName:     GemBox.Document.dll
OriginalFilename: GemBox.Document.dll
FileVersion:      2025.5.105.462
FileDescription:  GemBox.Document 2025.5 for .NET Framework 4.6.2
Product:          GemBox.Document 2025.5 for .NET Framework 4.6.2
ProductVersion:   2025.5.105.462+9b754b7fa0249a46974e36d2f4abccd9086814a3
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

SkiaSharp, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756
C:\DoNotBackup\CrimePad\gembox-demo\SkiaSharp.dll
File:             C:\DoNotBackup\CrimePad\gembox-demo\SkiaSharp.dll
InternalName:     SkiaSharp.dll
OriginalFilename: SkiaSharp.dll
FileVersion:      2.88.9.0
FileDescription:  SkiaSharp
Product:          SkiaSharp
ProductVersion:   2.88.9.0-eed06a83bea2a92b006c7cc7d9959689fb7b38c1
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

I have updated the github repo to show this issue.

Thanks in advance!

You’re missing native assets for SkiaSharp and for HarfBuzzSharp as well.
Please add them to your repo:
https://www.gemboxsoftware.com/temp/forum-1537/skia-and-harf-native-assets.zip

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:

1 Like