Thursday, September 4, 2008

Office application does not quit after automation from Visual Studio .NET client

This is the result of a known Microsoft issue -- if you directly reference any members of the Microsoft.Office.Interop.Excel COM objects, the objects will not terminate in spite of garbage collection and as a result, the EXCEL.EXE process will not terminate.

The workaround is to instantiate new objects as references to the same members, then forcibly release the COM object using System.Runtime.InteropServices.Marshal.ReleaseComObject, the objects will then terminate correctly by garbage collection, and the process now terminates as expected.

Here is the Microsoft kb identifying this issue and the workaround:

Office application does not quit after automation from Visual Studio .NET client
http://support.microsoft.com/default.aspx?scid=kb;en-us;317109

No comments: