Recently we added PDFNet to the Nuget gallery. For our .Net users this is a great new way to keep up on the latest PDFNet releases.

This package includes all of our .Net releases, for .Net 2.0 – 3.5 and .Net 4.0 +, and the corresponding 32 and 64 bit assemblies. When you install the package it of course picks the appropriate version and sets everything up for you.

A common pain that our .Net users have had, was using both our 32 and 64 bit assemblies in an AnyCPU project. While an installer would normally take care of this, it was still frustrating for developers. To address this issue, our Nuget package includes a new assembly, PDFNetLoader, that at runtime will pick the correct version of PDFNet. The source code for the loader is available on GitHub, and the latest binaries here.

If you install the nuget package, then all of this is setup for you, and before calling any PDFNet methods, simply insert the following line of code, in the main class of your project.

private static pdftron.PDFNetLoader loader = pdftron.PDFNetLoader.Instance();

You can also change the load path for the PDFNet assemblies, by appending the code above with


For example

private static pdftron.PDFNetLoader loader = pdftron.PDFNetLoader.Instance().Path(@"..\res");

linkTechnical Details

On the other hand, if you are already using PDFNet, or don’t want to use the Nuget package, here are the manual steps to setup your project to use PDFNet and AnyCPU.

First let us assume your output dir (where your exe is created) is ‘bin’.

  1. Create a folder in ‘bin’ called ‘PDFNet’
  2. In ‘PDFNet’ create two folders, one called ‘x64’, the other ‘x86’
  3. Place the PDFNet.dll for x86 and x64 in the respective folders above.
  4. Download the latest PDFNetLoader.dll :
  5. In your Visual Studio project add PDFNetLoader.dll as a reference.
  6. In your Visual Studio project add bin/PDFNet/x86/PDFNet.dll as a reference.
  7. Right click the PDFNet.dll (not PDFNetLoader.dll) in your references, and select Properties.
  8. Change the “Copy Local” property to “False”
  9. Somewhere in your code, as early as possible, and before any PDFNet methods are called, add the following line.
private static pdftron.PDFNetLoader loader = pdftron.PDFNetLoader.Instance();

You are now ready to run your project in AnyCPU.

The project references to PDFNet and PDFNetLoader allow you to code normally. At runtime though, the following will happen.

  1. The PDFNetLoader.Instance() method is triggered, which registers itself as an event handler for AppDomain.AssemblyResolve.
  2. JIT encounters a method that uses PDFNet and tries to load PDFNet.dll, but because of the “local copy:false” this fails.
  3. PDFNetLoader gets the AssemblyResolve event, detects if system is 32 or 64 bit, and loads the corresponding PDFNet.dll.

We hope our .Net users find this useful, and as always you can ask questions in PDFNet Forum on Stackoverflow.