ghost instance when Excel closes for packed add-in but not unpacked

55 views
Skip to first unread message

bpier...@gmail.com

unread,
Jun 21, 2025, 1:34:35 PMJun 21
to Excel-DNA
Hi Govert,

I have one more weird one -- I have an add-in that causes Excel to leave a ghost instance after closing Excel when I load the packed version ...but if I instead deploy the unpacked files, no ghost instance occurs. It's the 64-bit xll, and FYI that I do rename the packed file after packing it in case that matters.

I'm going to keep digging and will try to create and send a simple project that exhibits this, but wanted to post in case you are already aware of anything that may cause such behavior.

Below is my packing config to show the settings and libraries being packed.

Thanks,

Brian

  <ExternalLibrary Path="My.Excel.AddIn.dll" LoadFromBytes="true" Pack="true" ExplicitExports="false" ExplicitRegistration="true" IncludePdb="false" />
  <Reference Path="BouncyCastle.Cryptography.dll" Pack="true" />
  <Reference Path="CsvHelper.dll" Pack="true" />
  <Reference Path="DocumentFormat.OpenXml.dll" Pack="true" />
  <Reference Path="DocumentFormat.OpenXml.Framework.dll" Pack="true" />
  <Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
  <Reference Path="ICSharpCode.SharpZipLib.dll" Pack="true" />
  <Reference Path="Microsoft.Bcl.AsyncInterfaces.dll" Pack="true" />
  <Reference Path="Microsoft.Bcl.HashCode.dll" Pack="true" />
  <Reference Path="Microsoft.Exchange.WebServices.dll" Pack="true" />
  <Reference Path="Microsoft.Extensions.DependencyInjection.Abstractions.dll" Pack="true" />
  <Reference Path="Microsoft.Extensions.Logging.Abstractions.dll" Pack="true" />
  <Reference Path="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll" Pack="true" />
  <Reference Path="Microsoft.VisualStudio.Interop.dll" Pack="true" />
  <Reference Path="Renci.SshNet.dll" Pack="true" />
  <Reference Path="System.Buffers.dll" Pack="true" />
  <Reference Path="System.Formats.Asn1.dll" Pack="true" />
  <Reference Path="System.IO.Pipelines.dll" Pack="true" />
  <Reference Path="System.Memory.dll" Pack="true" />
  <Reference Path="System.Numerics.Vectors.dll" Pack="true" />
  <Reference Path="System.Runtime.CompilerServices.Unsafe.dll" Pack="true" />
  <Reference Path="System.Text.Encodings.Web.dll" Pack="true" />
  <Reference Path="System.Text.Json.dll" Pack="true" />
  <Reference Path="System.Threading.Tasks.Extensions.dll" Pack="true" />
  <Reference Path="System.ValueTuple.dll" Pack="true" />
  <Reference Path="My.Excel.AddIn.Windows.dll" Pack="true" />

Brian Pierce

unread,
Jun 21, 2025, 1:45:15 PMJun 21
to exce...@googlegroups.com
This is with the latest Beta, btw. Possibly it’s been the case for a long time - I’ll try a few older versions of DNA to see if it happens and will let you know.

One other piece of info that may or may not help: it also often hangs when debugging in Visual Studio. That is, if I close Excel the debug session keeps going because Excel is hanging on in the background. It’s clearly not loading the packed xll in that case, but I’m not sure what other factors may be at play.

Brian


On Jun 21, 2025, at 1:34 PM, bpier...@gmail.com <bpier...@gmail.com> wrote:

Hi Govert,
--
You received this message because you are subscribed to a topic in the Google Groups "Excel-DNA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/exceldna/LrGjcjnVHYI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to exceldna+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/3c70f3c9-567a-4437-a7ae-5d9248141112n%40googlegroups.com.

bpier...@gmail.com

unread,
Jun 23, 2025, 9:00:24 AMJun 23
to Excel-DNA
I'd say hold off on this, as recreation is not consistent. After bouncing my PC, I rarely get the ghost instances. Very strange. Maybe worth adding that this is a different PC from the last issue I reported (on this one I can use the ALT key to launch a 2nd Excel process while the add-in is loaded). I'm suspicious of recent Excel updates generally wreaking some havoc. Will follow-up if I can create a case that is recreatable with some reliability

Mike Sullivan

unread,
Jun 24, 2025, 10:13:30 AMJun 24
to Excel-DNA
One suggestion:
Never use ExcelDnaUtil.Application in anything other than a temporary variable inside a method. This has saved me after years of struggling to identify the source of random ghost EXCEL.EXE processes.

e.g.
public override void OnBeginShutdown(ref Array custom)
{
...
                var app = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
                app.SheetSelectionChange -= new Excel.AppEvents_SheetSelectionChangeEventHandler(eventSelectionChange);
                app.SheetActivate -= new Excel.AppEvents_SheetActivateEventHandler(eventSheetActivate);                
...
]



bpier...@gmail.com

unread,
Jun 24, 2025, 10:40:30 AMJun 24
to Excel-DNA
Thanks Mike. I was going to post an update, as I've narrowed it down a bit ...and I don't think it's necessarily even related to ExcelDna, at least not directly. One of the features in my add-in is to allow users to compile and run Python code, and that relies on Python.NET. I've found that the ghost instance occurs sporadically only when a Python function is compiled ...and it seems only if Excel is left open for 30+ seconds after compilation ...and generally only if debugging in Visual Studio or using a packed ExcelDna xll (weirdly can't recreate it referencing unpacked). So some bizarre interaction going on that may not be worth solving, but I'm going through the process of selectively removing code to see if I can identify the culprit.
Message has been deleted

bpier...@gmail.com

unread,
Jul 8, 2025, 1:25:18 AMJul 8
to Excel-DNA
In case anybody else ever has this issue, the problem is that I was calling the Python.NET PythonEngine.Shutdown() function in the Ribbon menu's OnBeginShutdown method. But that is not called in a macro context, which was the problem. Once I ensured I always did the cleanup of Python.NET in a macro context, all was well.
Reply all
Reply to author
Forward
0 new messages