ExcelDna
ExcelDna copied to clipboard
Unexpected NRE logged from QueueAsMacro in v1.1.0 (perhaps during startup)
The issue is from this discussion on the forum: https://groups.google.com/g/exceldna/c/_gZiX7IbSok
This error is logged
Runtime [Error] Unexpected error trying to run SyncMacro for queued macro execution. : NullReferenceException - Object reference not set to an instance of an object.
possibly under these conditions:
Apparently the details were as follows: no Excel instances were open, and it happened just as he opened a workbook containing external links and also both RTD and regular functions created with ExcelDNA (ExcelDNA Intellisense also used). No idea if the links thing is relevant, but apparently he has been launching sheets this way for a year without issue and started seeing this periodically since his addin was upgraded (the upgrade picked up ExcelDNA 1.1.0).
and now:
It's only anecdotal, but the issue has gone away since I rolled back to 1.0.
Some initial investigation.
I'm trying to have a look through the code here: https://github.com/Excel-DNA/ExcelDna/blob/63bedd0c00b8bf53e3708cee7b35cfde5b7c8551/Source/ExcelDna.Integration/ExcelSynchronizationContext.cs#L260
That's the only place where your message can come from. I can attempt to harden it a bit, but that will only help if there is some workaround for the problem scenario.
Now to see where a null reference could arise in that code, would note the following:
- _syncWindow cannot be null here, because we are in the window message handler for the sync window itself.
- _syncMacroName might be null during startup, if the RTD server starts before the add-in is loaded. This
- So the error comes from ComRunMacro() https://github.com/Excel-DNA/ExcelDna/blob/63bedd0c00b8bf53e3708cee7b35cfde5b7c8551/Source/ExcelDna.Integration/ExcelSynchronizationContext.cs#L374
- In here it could be one of three places:
- Inside
IsInFormulaEditMode()
, possible if we have gone down theCommandBars
fallback path afterCallPenHelper
fails. - Inside
ExcelDnaUtil.GetApplicationNotProtectedNoThrow()
- I can't see how this can throw aNRE
. -
Application.InvokeMember("Run"...)
returnsnull
- I'm not expecting this to ever happen.
Next steps to try would be to test this scenario:
- Define a fixed-ProgID RTD Server
- Have a workbook with RTD references to the server.
- Have some call to
ExcelAsyncUtil.QueueAsMacro
inside the RTD server. - Perhaps not load the add-in (.xll) itself, or not load it automatically.
- That would load the RTD server without the add-in - a scenario where the behaviour might have changed in v 1.1.
Hi @govert!
This issue reproduces quite reliably for us when we open a workbook in 2 windows and close the first window. This is the exception origin:
@sshukurov Can you confirm the version of Excel-DNA that you are using, and that it happens with the newest v1.6.0-preview3 ?
@govert we are using Excel-DNA v1.5.1.
I tried on v1.6.0-preview3 - the issue reproduces there, too.
@sshukurov Do you have the RTD server and other features first reported?
@govert the workbook contains links to external workbooks and also uses custom functions, but no RTD functions are used as far as I understand.
@sshukurov OK - could you try to narrow it down a bit to some instructions or an example I can try easily? E.g. are the links needed? Custom functions the are async using the ExcelAsyncUtil.Run
would be wrapping an RTD call. Does the error require the custom function calls in the sheets?