ExcelDna icon indicating copy to clipboard operation
ExcelDna copied to clipboard

Unexpected NRE logged from QueueAsMacro in v1.1.0 (perhaps during startup)

Open govert opened this issue 3 years ago • 8 comments

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.

govert avatar Jul 31 '20 20:07 govert

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:
  1. Inside IsInFormulaEditMode(), possible if we have gone down the CommandBars fallback path after CallPenHelper fails.
  2. Inside ExcelDnaUtil.GetApplicationNotProtectedNoThrow() - I can't see how this can throw a NRE.
  3. Application.InvokeMember("Run"...) returns null - I'm not expecting this to ever happen.

govert avatar Jul 31 '20 20:07 govert

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.

govert avatar Jul 31 '20 20:07 govert

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: image

sshukurov avatar Mar 12 '22 15:03 sshukurov

@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 avatar Mar 13 '22 08:03 govert

@govert we are using Excel-DNA v1.5.1.

I tried on v1.6.0-preview3 - the issue reproduces there, too.

sshukurov avatar Mar 14 '22 07:03 sshukurov

@sshukurov Do you have the RTD server and other features first reported?

govert avatar Mar 14 '22 07:03 govert

@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 avatar Mar 14 '22 08:03 sshukurov

@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?

govert avatar Mar 14 '22 11:03 govert