in Windows 8.1, Exception is being thrown when the Word Automation(using office2007) run in System Service context. RRS feed

  • Question

  • Hello,

    Below code which throws an exception, When run the Word2007 automation in System service context. This issue happened in Windows 8.1 system.

    Guid clsid = new Guid("{000209FF-0000-0000-C000-000000000046}");               

     Type servreType = Type.GetTypeFromCLSID(clsid);;
     object theServer = Activator.CreateInstance(ServerType);

     Type typeof_Server = theServer.GetType();

     typeof_Server.InvokeMember("Visible", BindingFlags.SetProperty, null, theServer
                                         , new object[] { true });
     typeof_Server.InvokeMember("DisplayAlerts", BindingFlags.SetProperty
                                         , null, theServer, new object[] { false });

     object documents = typeof_Server.InvokeMember("Documents", BindingFlags.GetProperty, null, theServer, null);

     object theActiveDocument = documents.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, documents
                                                                   , new object[] { objFileName0, Type.Missing, Type.Missing, Type.Missing
                                                                   , Type.Missing, Type.Missing, Type.Missing, Type.Missing
                                                                   , Type.Missing, Type.Missing, Type.Missing, Type.Missing
                                                                   , Type.Missing, Type.Missing, Type.Missing, Type.Missing});

            object sections = theActiveDocument.GetType().InvokeMember("Sections", BindingFlags.GetProperty
                                                                       , null, theActiveDocument, null); // Exception thrown here.[
    Exception from HRESULT: 0x800ADF21]
     catch (Exception exp)
            string strError = exp.Message;



    Monday, April 14, 2014 1:52 PM


  • Hello karthikeyan,

    Please take a look at the Considerations for server-side Automation of Office article. It states the following:

    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.

    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.

    I'd suggest using the Open XML SDK for working with open XML documents. Also you can find commercial components for working with old binary Office file format - .doc.

    Monday, April 14, 2014 2:09 PM