0

I have an application that uses Word Interop

Microsoft.Office.Interop.Word.Application word = null;
word = new Microsoft.Office.Interop.Word.Application();
//word.ReadFile
//word.SaveAs

It was working fine on one of our servers, however we recently got a new one. New server has Word from the Office Professional Plus 2016 installed (no other applications like Excel or others). On the new server I CAN run this application from my account (this tells me that all components are present on the machine).

However if application is run from the service account, it gets

System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)

This looks like an access issue, but I can not pinpoint which particular permission service account is missing. Trying to debug this situation I even gave service account administrator access but it didn't solve the issue.

Any thoughts or suggestions would be greatly appreciated!

P.S. Yes I know MS doesn't recommend it, however I was using Office Automation with success on many projects before, and this particular application was working on another machine. I'm hopeful to find resolution for this issue.

shlasasha
  • 165
  • 1
  • 14

2 Answers2

0

this thread helped me to find partial solution. In my case it was using DCOMCNFG.exe open it and go to Component Service ->Computers->My Computer->DCOM Config-> Office Licensing COM Server 16 ->Properties->Security->Launch and Activation Permission->select Customize and click on edit and the add the user that will runs your Application with full access

Unfortunately this is only partial solution. I can "Run AS" my application now but when set on the Task Scheduler it gets the same error. I keep searching....

shlasasha
  • 165
  • 1
  • 14
0

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

Consider using Open XML SDK if you deal with open XML documents only, see Welcome to the Open XML SDK 2.5 for Office for more information. Or just try to use any third-party components components designed for the server-side execution.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I am sorry but this is BS. I know Microsoft does not recommend bla bla bla, however I was using this functionality over years and it never been a problem. In this case it is clearly an access issue on a weirdly configured server machine. I can't believe it can not be resolved. But thank you for the input anyway :) – shlasasha Jan 10 '18 at 21:14