Using PDFNet in a WCF solution: Resolving 'invalid handle' issue

57 views
Skip to first unread message

Support

unread,
Mar 18, 2013, 2:04:28 PM3/18/13
to pdfne...@googlegroups.com

Q:

I have a large VS2010 SharePoint solution consisting of about 10 projects. So .net 3.5.

 

One solutions is a basic “tools” package that provides support functions, webparts, ribbon buttons, etc. to the other solutions. This is where PDFNet 5.9.2 is referenced (and is configured to deploy to the GAC).

 

Your library works fantastically, everywhere. I have timer jobs that optimize pdfs on the file system, I have ribbon buttons to join pdfs together, convert images to pdf, event handlers that optimize pdfs attached to inbound emails, etc. Spectacular.

 

This weekend I attempted to add to the solution a WCF service to accept pdfs as byte[], optimize and return them, over a web service. Everything about the WCF part works fine right up to the point where it tries to initialize the PDFNet when it stops and complains it can’t load the file or assembly PDFNet 5.9.2… The handle is invalid.

 

Every other aspect  of this project that requires your dll works perfectly, all in the same debug session.  So the DLL is in the gac and is accessible.

 

Normally “handle is invalid” would lead me to believe I have a 32/64 bit issue (e.g. https://groups.google.com/d/msg/pdfnet-sdk/Op5m-2VH2ww/2qSjM8PGRzAJ), except that other components of the project that invoke the dll work fine, again in the same debug session.

 
-----------
A: 
 
After writing that thing out it helped me think about the problem from a different perspective.  

Adding your DLL to the assemblies section of web.config per this article resolved it:

 

http://stackoverflow.com/questions/1487218/wcf-service-unable-to-load-referenced-assemblies-from-the-gac

 

Support

unread,
Mar 18, 2013, 5:57:03 PM3/18/13
to
FYI: Passing additional info from the customer...

---
 
If this ever comes up with any of your other customers there's two other things to know when accessing DLLs through WCF and SharePoint:
 
1. After adding the assembly to web.config, the compiler will start throwing this (apparently) ignorable error:

     

2.  Additionally, any SharePoint code that needs to read/write temp files (e.g. The PDFNet Optimizer and Converter) needs to be run using SPSecurity.RunWithElevatedPrivileges:

 

 

  Thanks for your great library.
Reply all
Reply to author
Forward
0 new messages