Error When Closing Excel from C# Application

Oct 29, 2012 at 3:05 PM

I am getting the following error when trying to close Excel from a C# application.  I am using the following lines of code to close Excel.

workbook.DisposeChildInstances();

app.Quit();

app.Dispose();

Below is the error message I am getting.  An unhandled exception is occuring when the c# application closes out Excel.

 System.Runtime.InteropServices.InvalidComObjectException: Attempt has been made to use a COM object that does not have a backing class factory.

Coordinator
Oct 29, 2012 at 3:59 PM
Edited Oct 29, 2012 at 4:02 PM

hello,

first time i see a problem like this. do you have a full source listing for me?
its not cleary for me in which line cause the exception. app.Dispose(); ???

the message indicates for me the proxy is already death yet. you can check with app.IsDisposed or workbook.IsDisposed for the information if the com proxy is already disposed. the bool IsDisposed property is hidden from intellisense.

Sebastian

Oct 29, 2012 at 5:43 PM

Here is the entire problem message I am getting.

System.Runtime.InteropServices.COMException (0x80004005): See inner exception(s) for details. ---> System.Runtime.InteropServices.InvalidComObjectException: Attempt has been made to use a COM object that does not have a backing class factory.
   at NetOffice.Invoker.PropertyGet(COMObject comObject, String name, Object[] paramsArray)
   at NetOffice.Invoker.PropertyGet(COMObject comObject, String name, Object[] paramsArray)
   at NetOffice.ExcelApi._Worksheet.get_Range(Object cell1, Object cell2)
   at WindowsFormsApplication1.CreateExcelDoc.excelTimer_Tick(Object sender, EventArgs e) in C:\Users\CPhillips\Documents\Visual Studio 2010\Projects\ObedianceTrialSoftware - Copy\WindowsFormsApplication1\trialReportForm.cs:line 3631
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Coordinator
Oct 31, 2012 at 5:37 PM

i see you use a timer and i need more informations in this case. what i think is the application is destroyed and the timer try access the dead application.
you can send me a simplified example to my mail adress again.

Sebastian