2013-06-03 124 views
0

我收到錯誤: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幻燈片的圖像和文本對象。它們在編輯器中被進一步使用。 –

回答

2

好的,就是這樣。我提到了所有可能的解決方案。從殺害,退出,關閉,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

相關問題