Got TypeInitializationException before calling PDFNet.Initialize()

I have downloaded the trial version and followed available examples to load the sameple .xod file onto the WebViewer embedded in a web page without problems.

In order to load the existing files onto the viewer from our file system, I call pdftron.PDFNet.Initialize() and then pdftron.PDF.Convert.ToXod(input_pdf, output_xod). However the following exception was given prior to reaching the Initialize() call in my method (GetXODFilePath below):

1) Exception Information
Exception Type: System.TypeInitializationException
TypeName: <Module>
Message: The type initializer for '<Module>' threw an exception.
TargetSite: System.String GetXODFilePath(Int32, System.String, System.String, Int32, Int32)
HelpLink: NULL
HResult: -2146233036

2) Exception Information
Exception Type: <CrtImplementationDetails>.ModuleLoadException
Message: The C++ module failed to load while attempting to initialize the default appdomain.

TargetSite: Void <CrtImplementationDetails>.LanguageSupport.Initialize(<CrtImplementationDetails>.LanguageSupport*)
HelpLink: NULL
Source: PDFNet
HResult: -2146233088

I got the same exception even though I have the Microsoft Visual C++ 2012 Redistributable (x64) installed which was suggested in another thread.

I also read this article "Converting Documents on a Windows Service or ASP.NET Application using PDFNet SDK" ( and followed the recommended way to isolate the conversion process.

So I added the WebViewerConvertTest project to my existing web solution. I see the module file has PDFNet.Initialize() in place at the very beginning. Running the console app has no problem within VS2012.

Now in my Ajax function GetXODFilePath(), I attempted to start a process to get the server file converted to XOD format and return back to the client to load it onto the web viewer, by doing this within the function:

Dim proInfo As New ProcessStartInfo
With proInfo
    .FileName = "PDFTron/WebViewerConvertTest.exe"
    .Arguments = String.Format("{0} {1}", serverFileName, tempXODFileName)
    .CreateNoWindow = True
    .UseShellExecute = False
End With
Return tempXODFileName

But again, before reaching the GetXODFilePath(), the TypeInitializationException is thrown already. So what was I missing or what other tricks that I need to do to resolve this problem? Is it related to the demo mode or licensing?

Thanks for helping in advance.


Because PDFNet for .Net contains unmanaged code, it has additional requirements when crossing appdomains (since managed and unmanaged are in different memory regions).

If you are using a security package with a class implementing IPrincipal, then you must inherit from the MarshalByRefObject class.

For more information see the following.!topic/ausdotnetlist/9tGDLXklfZw