Excel-DNA / Excel-DNA/ExcelDna

excel crash on adding ToolStripMenuItem objects in a .NET Windows.Form twice in version 1.9

Open
#859 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.5k
Forks
292
Avg merge
20d 12h
Merged PRs (30d)
1

Description

After upgrading to exceldna 1.9.0 I've experienced crashes when opening a Windows.Form that adds a context menu by using ToolStripMenuItem objects. Essentially only eliminating any calls to ToolStripMenuItem like these helps:

```VB.NET
Dim eventHandler As New System.EventHandler(AddressOf contextMenuClickEventHandler)
newStrip = New ToolStripMenuItem(text:=Folderpath + Left$(fileList(i).Name, Len(fileList(i).Name) - 4), image:=Nothing, onClick:=eventHandler) With {
.Tag = rootPath + "\" + fileList(i).Name,
.ToolTipText = "click to insert configured select statement for " + Left$(fileList(i).Name, Len(fileList(i).Name) - 4) + ". Ctrl or Shift + click to display documentation for config if existing."
}
currentStrip.DropDownItems.Add(newStrip)
```

The interesting part here is, that this is only observable on certain builds, e.g. Version 2408 Build 16.0.17932.20574.
On higher builds like Version 2408 Build 16.0.17932.20602 this doesn't appear anymore, so there's also a memory management problem involved.

However I'm interested in getting this fixed once for all and I have heard that instantiating handlers while not on the main thread of excel is asking for trouble. Also on exceldna 1.6.0 this wasn't causing these crashes.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Windows.Form context-menu setup that adds ToolStripMenuItem objects twice, using Excel-DNA 1.9.0 on the affected Excel build. Compare behavior with Excel-DNA 1.6.0 and the listed higher Office build; done means the form opens without crashing while retaining the context menu.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.