Got TypeInitializationException before calling PDFNet.Initialize()

167 views
Skip to first unread message

Erica Li

unread,
Mar 13, 2015, 1:56:00 PM3/13/15
to pdfne...@googlegroups.com
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" (http://www.pdftron.com/pdfnet/faq_files/Converting_Documents_in_Windows_Service_or_ASP.NET_Application_using_PDFNet.pdf) 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
Process.Start(proInfo)
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.

Erica

Ryan

unread,
Mar 13, 2015, 9:12:58 PM3/13/15
to pdfne...@googlegroups.com
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.

http://world.episerver.com/blogs/Svante-Seleborg/Dates/2011/10/The-type-initializer-for-Module-threw-an-exception/
https://groups.google.com/forum/#!topic/ausdotnetlist/9tGDLXklfZw
http://forums.lhotka.net/forums/p/4366/22838.aspx
http://stackoverflow.com/questions/1884030/implementing-a-custom-identity-and-iprincipal-in-mvc

Reply all
Reply to author
Forward
0 new messages