Search code examples
c#office365powerpointoffice-automationdcom

MS PowerPoint Presentations.Open method fails


I am trying to find out why the object of Microsoft PowerPoint application doesn't want to open pptx file. This is what I have (C#):

        using PowerPoint = Microsoft.Office.Interop.PowerPoint;
        using MSBool = Microsoft.Office.Core.MsoTriState;
        private void button2_Click(object sender, EventArgs e)
        {
            PowerPoint.Application oPowerPointApp = new PowerPoint.Application();
            oPowerPointApp.Activate();
            oPowerPointApp.Visible = MSBool.msoTrue;
            oPowerPointApp.Presentations.Open("c:\\mypp\\pptx001.pptx");
        }
 

I am getting this exception when Open method is been called: **System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.' **

I have Microsoft 365 MSO (Version 2211 Build 16.0.15831.20220) 64-bit
Windows 10 64 bit

MSExcel application works just fine. I am wondering if somebody had this kind of issues and have a solution. Any help would be greatly appreciated.

I tried to:

  1. Tweak values of DCOM for Microsoft PowerPoint previewer (Security and Identity tabs)
  2. Reinstall PowerPoint (MS Office)
  3. Call to Open method with all kinds of different combinations of arguments
  4. Install Nuget package Microsoft.office.Interop.PowerPoint

Solution

  • System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.'

    This is a widely spread error when Office applications are automated on the server or form any service applications. Here is what MS states for such scenarious:

    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.

    If you deal with open XML documents only you may consider using the Open XML SDK instead. See Welcome to the Open XML SDK 2.5 for Office for more information.