Xod Conversion - Windows Service Fails to Start

27 views
Skip to first unread message

David Compton

unread,
Jan 3, 2017, 12:40:09 PM1/3/17
to PDFTron WebViewer
I have created a Windows Service that (along with other database related processes) converts files to XOD format. All of the code run by the service exists in a separate class library which I call my "engine".  During development I test the engine by running its code from a WPF application that mimics what happens when my service runs.  So I know that all is working fine in regards to converting to XOD.  However when I go to start my Windows service (either locally on my development machine or on my server) I get the following error:

Application: BTT.DocsOnTap.UserDbService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(System.String, System.Security.Policy.Evidence, Byte[], System.Configuration.Assemblies.AssemblyHashAlgorithm, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
   at System.Reflection.Assembly.LoadFrom(System.String)
   at pdftron.PDFNetLoader.PDFNetResolveEventHandler(System.Object, System.ResolveEventArgs)
   at System.AppDomain.OnAssemblyResolveEvent(System.Reflection.RuntimeAssembly, System.String)

Exception Info: System.IO.FileNotFoundException
   at BTT.DocsOnTap.UserDbService.UserDbService..ctor()
   at BTT.DocsOnTap.UserDbService.Program.Main()

My service constructor looks like this:

    public partial class UserDbService : ServiceBase
    {
        ......
        private static PDFNetLoader _loader = PDFNetLoader.Instance();  ******

        public UserDbService()
        {
            pdftron.PDFNet.Initialize();  ******
            InitializeComponent();
            CanStop = true;
            _log.Info("Service initialized");
        }

        ......
    }

If I remove the 2 lines marked with astrisks then my service starts OK.  In my WPF application all works OK with the calls to the Loader and Initialize (I have these 2 lines in my MainWindow.xaml.cs).

Can you suggest what I need to do to get things to work with the Loader and Initialize calls in my Windows Service (I've also included a screen shot of my bin/Debug directory for the service.



Thanks,

David
Auto Generated Inline Image 1

Ryan - PDFNet Developer

unread,
Jan 3, 2017, 6:37:28 PM1/3/17
to PDFTron WebViewer
Hello David,

The PDFNetLoader class is just a "helper" file to allow people to run our samples under the AnyCPU configuration in VisualStudio, since PDFNet comes in 32 and 64bit versions.

The code for PDFNetLoader is here, and as you can see does nothing else.

When PDFNetLoader calls Assembly.LoadFrom(path) .Net treats the path as a URL network resource to an untrusted source, and this can fail, depending on your application settings. 

Our SDK samples fix this by adding the line loadFromRemoteSources set to true in the App.Config.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
<runtime>
   
<loadFromRemoteSources enabled="true" />  
 
</runtime>
</configuration>

The easier fix though, since you are deploying to a server, is to simply remove PDFNetLoader from your project, and directly reference the version of PDFNet you want to use, and set copyLocal:True property of the assembly.

This blog goes into more details if you are interested.

David Compton

unread,
Jan 5, 2017, 12:55:33 PM1/5/17
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
Hi Ryan,

Thanks for you response.  In the end I did remove the PDFNetLoader and directly referenced the x86 version of the PDFNet.dll.  For some reason the x64 version still caused an error - even though it is running on a 64 bit machine.  

Regards,

David

--
You received this message because you are subscribed to the Google Groups "PDFTron WebViewer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfnet-webviewer+unsubscribe@googlegroups.com.
To post to this group, send email to pdfnet-webviewer@googlegroups.com.
Visit this group at https://groups.google.com/group/pdfnet-webviewer.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages