Creating visio file is working from console app but not working from windows service

Viewed 521

I have following code which opens visio file:

Microsoft.Office.Interop.Visio.Document vXfuncStencil = null;
var app = new Microsoft.Office.Interop.Visio.Application();
vXfuncStencil = app.Documents.OpenEx(@"C:\Program Files\Microsoft Office\Office16\Visio Content\1033\XFUNC_U.VSSX", 4);
app.Quit();

It works fine in console app but gives following error when I run through windows service:

System.Runtime.InteropServices.COMException (0x86DB03E7): An exception occurred. at Microsoft.Office.Interop.Visio.DocumentsClass.OpenEx(String FileName, Int16 Flags) 

Some notes:

  1. We run our job as Windows Service under a specific service account (also added as Local Administrator on the server)
  2. We can't find any information about the error: 0x86DB03E7.
  3. We are running code in Azure VM - windows server 2019 (64 bit), visio 2016 64 bit
  4. The same application working fine on our on-premise server. We are migrating to Azure server and it's not working. We compared all the setting on both the server.

Does anyone know what the error 0x86DB03E7 is about? Why it's not working from windows service?

3 Answers

It worked on Windows server 2012 after doing DCOM configuration changes:

  • Install visio on the server
  • Start > Run > dcomcnfg
  • Navigate to Component Services > Computers > My Computer > DCOM Config
  • Locate Microsoft Visio 2003-2010 Drawing
  • Right click > Properties
  • On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
  • Add [Your User] and assign Local Launch & Local Activation permissions
  • On the identity tab make sure the process is set to run as "This User:" and put in the [Your User] account and password.

For Windows server 2019: We consulted Microsoft support and they said: "All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.".

Visit https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office for more detail.

They suggested to use Open XML SDK to create and manipulate visio files. Visit https://docs.microsoft.com/en-us/office/client-developer/visio/visio-file-format-reference for more detail.

As described in this article, Microsoft Office applications may encounter problems when run in the context of a Windows Service. Many operations simply won't work.

To have any hope of launching Visio, you must run your service in a "regular" Windows account — one where you have installed Visio and can start it normally/interactively. A specific service account won't be sufficient if you have never installed Visio there.

For Visio to run as a Windows Service (in the background), make sure the folders "Desktop" and "Documents" exist under:

C:\Windows\sysWOW64\config\systemprofile

C:\Windows\system32\config\systemprofile

Related