1
Answer

Problem with Word Function in DLL class when called from Windows Service

Photo of Neal

Neal

18y
1.8k
1

Hi,

I'm not really sure where I should be posting this one, it's in the area of Word Interop, Windows Services and Asynchronous programming...

I have a Class Library DLL, which contains a function that processes a Word document (opens Word, does some stuff, quits Word). The class library contains another function that basically just wraps this to allow it to be called asynchronously.

When I include the DLL in a Windows Forms project I have and run it - it works fine, but when I include the DLL in the Windows Service project, it fails to process the Word Document, and also leaves Word open - even though the code goes into the catch section of the Try catch block which contains a Word.Quit.

Answers (1)

0
Photo of Sokak
NA 43 2k 18y
Have you attached the Visual Studio debugger to the service to follow exactly what is going on?

Typically anything that falls into "Works as an application, fails or behaves unexpectedly as a service" boils down to security permissions. After you set up the service, try configuring it to run using your own login credentials (as a test) and see what it does. Essentially that should make your service behave the same as an Exe. The other key difference is the executing path, as a service it doesn't execute from the location you install the assemblies, if memory serves me it runs in Windows/System32. (XP) I believe it finds .config files ok, but if you use GetExecutingAssembly or relative paths you may be hitting snags.