System.Runtime.InteropServices.COMException(0x80080005)

问题描述:

我收到错误:System.Runtime.InteropServices.COMException(0x80080005)

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.

为这里的代码块行PowerPoint.Application PowerPoint_App = new PowerPoint.Application();

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); 
    } 
} 

每当我跑该代码第一次,它完美的作品,但它然后创建PowerPoint的过程(可以在任务管理器中看到)。我用PowerPoint_App.Quit();退出已经打开的进程,但它不起作用,并引发错误。我去任务管理器并从那里结束进程,然后就可以再次工作了。

我退出代码的过程中做错了什么,或者有什么其他的方式吗?

+0

是显示在同一时间一个错误的PowerPoint的用户界面? Powerpoint COM服务器在受到很大压力时可能会很容易失败(例如,在一个循环中)。 –

+0

我不打开ppt ui.i使用来自ppt幻灯片的图像和文本对象。它们在编辑器中被进一步使用。 –

好的,就是这样。我提到了所有可能的解决方案。从杀害,退出,关闭,Marshal.FinalReleaseComObject,GC Collect和WaitForPendingFinalizers。但没有为我工作。所以我发现了正在运行的进程并通过代码杀死了它。而巴恩一切都按照我的预期工作。

代码:

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

命名空间要求:

System.Diagnostics

Application.Quit() method failing to clear process

还有一个选项,让您的apllication检查,看是否exe文件运行的,企图在最后,但我强烈建议针对手动杀死它。