Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4627588
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:35:19+00:00 2026-05-22T03:35:19+00:00

When using COM Interop with Office (usually Excel), I always carefully ensure I call

  • 0

When using COM Interop with Office (usually Excel), I always carefully ensure I call Marshal.ReleaseComObject on every reference, to avoid the problem where Excel doesn’t quit as described in this KB article.

How can I ensure Excel quits when I use Interop from an OOB Silverlight application (with AutomationFactory.CreateObject)?

Silverlight doesn’t have a Marshal.ReleaseComObject method and even calling GC.Collect and GC.WaitForPendingFinalizers doesn’t help.

Surely Microsoft hasn’t added this feature to Silverlight without a mechanism to release COM references? This seems to me to be a showstopper for automating out-of-process COM servers such as Excel.

A surprising ommission, all the more so as Pete Brown in section 5.5 of his book “Silverlight 4 in Action” goes as far as to say about AutomationFactory.CreateObject, that:

The primary intent of this feature is to allow automation of other applications, including Microsoft Office.

UPDATE in response to Hans’ comments.

I’m not convinced the “silent assassin” problem exists in typical automation of Office apps. A common use might look something like the following, which I’ve seen used repeatedly in WinForms applications without ever coming across the “poisoned RCW” described in the article linked by Hans:

  • Create an Excel.Application instance
  • Open or create a workbook
  • Write data to the workbook
  • Show Excel if all went well, close the workbook and call Application.Quit if not.
  • Call Marshal.ReleaseComObject to release all Excel object references.

Failing to call Marshal.ReleaseComObject as recommended by Hans will leave multiple copies of Excel.exe running, as described in the KB article mentioned above – highly undesirable.

UPDATE 2

The sample I’m using to repro this is a sample from the source code for Pete Brown’s book Silverlight 4 in action, there’s a download link on this page. The sample solution AutomatingExcel is in Ch05.zip / 5.03. To repro:

  • Make sure no instances of Excel are running
  • Run AutomatingExcel sample
  • An Excel workbook is opened
  • Close Excel
  • Observe with Task Manager that Excel is still running.

Setting all the dynamic variables to null and calling GC.Collect() seems to work as pointed out in AnthonyWJones’s answer.

UPDATE 2

Otaku’s answer is what I was looking for – by wrapping references in a using statement the COM references are released without the need to call GC.Collect. A bit of experimentation shows that it’s more tolerant of failing to dispose every single reference, unlike the standard Marshal.ReleaseComObject solution described in the KB article referenced above.

It would be interesting to have an authoritative take on exactly what must be disposed to ensure that all Excel references are released.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:35:20+00:00Added an answer on May 22, 2026 at 3:35 am

    You could implement the IDisposable interface. The best example of this I’ve seen is at http://csfun.blog49.fc2.com/blog-entry-79.html. The blog entry is in Japanese, but open in Chrome and let Google do the page translation for you if you don’t read Japanese.

    Also, if you just want the source code example of the COM wrapper directly you can download the sample app it comes in: SilverOffice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm opening an excel worksheet using the Microsoft.Office.Interop.Excel COM interface. I'm trying to adjust
I'm writing an Excel Addin using COM Interop from .net. I have a command
I am trying to call a COM object from PHP using the COM interop
I'm trying to find a way using the Office.Interop.Outlook COM object to connect to
In my web application, I am using Microsoft.Office.Interop.Excel to generate a pivot table in
I'm using the COM objects from Office 2007 to handle and print ms-office files.
when adding a reference I see: .net tab microsoft.office.tools.excel is that the one I
I'm trying to do office 2003 interop using C# ASP.NET on a server running
I'm using Delphi 2009 and the MS Access Interop COM API. I'm trying to
Am using COM interop in my C# application. I've this line of code: IMyInterface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.