0

I am getting the error:

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80080005.

for line PowerPoint.Application PowerPoint_App = new PowerPoint.Application();

for this block of code here:

using (new Impersonator(Installs.Current.PPTUser, null, Installs.Current.PPTPassword))
{
    PowerPoint.Application PowerPoint_App = new PowerPoint.Application();
    PowerPoint.Presentation presentation = null;
    try
    {
        PowerPoint_App.Visible = MsoTriState.msoTrue;
        presentation = PowerPoint_App.Presentations.Open(
            strPptFilePath, Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoTrue);

        for (int i = 0; i < presentation.Slides.Count; i++)
        {
            readSlides(presentation, i);
        }
        presentation.Close();
        PowerPoint_App.Quit();
    }
    catch (Exception ex)
    {
        strSuccess = ex.ToString();
        MindMatrix.Libraries.Entities.ExceptionMessage.HandleException(ex, null);
    }
    finally
    {
        Marshal.FinalReleaseComObject(presentation);
        Marshal.FinalReleaseComObject(PowerPoint_App);
    }
}

whenever I run the code for the first time, it works perfectly, but then it creates process for PowerPoint (which can be seen in Task Manager). I have used PowerPoint_App.Quit(); to quit the already open process, but it's not working and throwing me error. I go to Task Manager and end process from there and then it's ready to work for one more time.

Am I doing something wrong while quitting the process from code or is there any other way to do it?

sharptooth
  • 167,383
  • 100
  • 513
  • 979
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • Is the powerpoint UI showing an error at the same time? Powerpoint COM server can fail quite easily if stressed heavily (in a loop for example). – Simon Mourier Jun 03 '13 at 15:16
  • I am not opening ppt ui.i am using images and text objects from ppt slides.They are further used in editor.. – Milind Anantwar Jun 03 '13 at 15:35

2 Answers2

3

All right,that's how it went. i referred all the possible solution i can. from killing,quitting ,closing,Marshal.FinalReleaseComObject,GC Collect and WaitForPendingFinalizers. But nothing worked for me. so i found out the running process and killed it through code. And bamn everything works the way i expected.

Code:

  Process[] pros = Process.GetProcesses();
    for (int i = 0; i < pros.Count(); i++)
         {
           if (pros[i].ProcessName.ToLower().Contains("powerpnt"))
                {
                  pros[i].Kill();
                }
         }

Namespace Required:

System.Diagnostics

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

See Application.Quit() method failing to clear process

There is also the option, of having your apllication check to see if the exe is running, attempt to kill it manually in your finally, but I highly advise against that.

Community
  • 1
  • 1
Bruce Burge
  • 144
  • 1
  • 15