Custom Ribbon Page with BloombergAddin - One Excel Instance Process is Stuck

35 views
Skip to first unread message

Ranjith Kaluvala

unread,
Sep 27, 2022, 6:19:49 PM9/27/22
to Excel-DNA
Hi All 

I am facing wierd ReleaseComObject issue. We have a In-house Excel AddIn built using Excel DNA. We built a custom Ribbon with few buttons. Clicking on the button it loads macro enabled Excel (i.e. xlsm). I am using ExcelDnaUtil.Application Workbooks Open method to load the xlsm. Once the file is loaded using OnAction Event. I am making sure to release all the Com Objects using Marshal.FinalReleaseComObject. Also calling GC Collect and GC WaitForPendimgFinalizers. I am also checking for Marshal AreComObjectsAvailableForCleanUp in a loop to call GC methods. Everything works as expected without Bloomberg Add-In. When we launch our Add-In with Bloomberg Add-In and click on the Ribbon button, there is an Excel instance getting stuck and running under Users Profile. Another wierd issue is In task Manager => Process tab all instances gets removed immediately when we close the Excel. But Task Manager => Users Tab shows excel instance. Btw we are using 32 bit excel 365. If I remove the Bloomberg Add-In and load the ribbons and xlsm everything works as expected. 

Anyone faced this kind of issue with Bloomberg Add-In & Excel DNA? Any alternate solutions is appreciated.

Govert van Drimmelen

unread,
Sep 28, 2022, 1:59:35 AM9/28/22
to exce...@googlegroups.com

Hi Ranjith,

 

When doing COM interop from and Excel-DNA add-in, there is one key rule you should follow:

  • All access to the COM object model MUST be from the main Excel thread (ManagedThreadId == 1)

 

If you follow this rule you NEVER have to call Marshal.FinalReleaseComObject or explicitly call the garbage collector.

The Excel process should exit properly after closing the app.

 

I suggest you:

  • add some debug checks in your add-in to ensure you are following this rule – just make sure you are not starting tasks which run on other threads and call the COM object model, any timers that you might have run on the main thread etc.
  • Then remove all calls in your code to Marshal.ReleaseComObject and the GC.Collect.
  • Then check that your add-in (without Bloomberg loaded) does not interfere with Excel shutting down.

 

After you’ve done this, if you still find Bloomberg giving trouble when your add-in is loaded:

  • Make a tiny Excel-DNA add-in with minimal features – maybe just one simple function and a ribbon with some small callback that writes using the COM object model.
  • Check that this minimal add-in works fine on its own – Excel shuts down properly etc.
  • Check whether this minimal add-in is still interfered with by Bloomberg.
  • If it does, then report the problem to Bloomberg. I’m happy to help them if they have any questions, but don’t have access to Bloomberg myself, so can’t really help debug that scenario.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/cb6aeb30-6faa-465a-8f52-8cd5ecbcb454n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages