Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top