With the release of our Nuget package, was improved AnyCPU support for .Net.
https://www.nuget.org/packages/PDFNet/
However, for our existing clients, you can also get the benefit of this setup without using nuget, by following these instructions.
First let us assume your output dir (where your exe is created) is ‘bin’.
- Create a folder in ‘bin’ called ‘PDFNet’
- In ‘PDFNet’ create two folders, one called ‘x64’, other is ‘x86’
- Place the PDFNet.dll for x86 and x64 in the respective folders above.
- Download PDFNetLoader.dll : https://github.com/PDFTron/PDFNetLoader/releases/download/v1.0.0.0/PDFNetLoader.dll
- In your Visual Studio project add PDFNetLoader.dll as a reference.
- In your Visual Studio project add bin/PDFNet/x86/PDFNet.dll as a reference.
- Right click the PDFNet.dll (not PDFNetLoader.dll) in your references, and select Properties.
- Change the “Copy Local” property to “False”
- Somewhere in your code, as early as possible, and before any PDFNet methods are called, add the following line.
private static pdftron.PDFNetLoader pdfnet = 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.
- the PDFNetLoader.Instance() method is triggered, which registers itself as an event handler for AppDomain.AssemblyResolve
- JIT encounters a method that uses PDFNet and tries to load PDFNet.dll, but because of the “local copy:false” this fails.
- PDFNetLoader gets the AssemblyResolve event, detects if system is 32 or 64 bit, and loads the corresponding PDFNet.dll.
The source code for the loader is here: https://github.com/PDFTron/PDFNetLoader/releases
Also, if you want to change the load path, you can all
private static pdftron.PDFNetLoader pdfnet = pdftron.PDFNetLoader.Instance().Path("my_path_to_folder_containing_x86_and_x64_subfolders");
And PDFNet will look for subfolders called x86 and x64 in the specified dir.
We are looking for feedback, so feel free to contact us with how it went if you try.