Addin crashes Excel after UDF

47 views
Skip to first unread message

AE

unread,
Jan 12, 2022, 8:08:19 AMJan 12
to Excel-DNA
I have one user where addin crashes Excel every time they recalc the worksheet.

For example, the user selects a cell containing UDF, presses F2 and Enter. Excel crashes.

The UDF is marked as thread safe.

There is the following entry in Event Viewer:

Screenshot 2022-01-12 160734.png

Thanks!


AE

unread,
Jan 12, 2022, 8:11:18 AMJan 12
to Excel-DNA
I placed logs everywhere in the function. The crash happens right after the value is returned. 

Govert van Drimmelen

unread,
Jan 12, 2022, 9:33:07 AMJan 12
to exce...@googlegroups.com

--------------------------------------------------

Excel-DNA is now registered on GitHub Sponsors.

Please set up a small monthly contribution to encourage support and development.

--------------------------------------------------

 

Can you confirm the Excel-DNA version that is happening with?

 

You say the problem occurs for one user.

Does it work fine on other machines?

Does the error happen repeatable on that machine with the F2 action?

Does it happen when the formula is entered normally the first time?

Do you know of any differences between the machine with problems and tother machines, e.g.

  • Excel version
  • .NET Framework version
  • Processor type
  • VBA or other add-ins or macros that might be listening to the Excel object model events

 

From the stack trace in the error it looks like you are using the Excel native async mechanism, through the Excel-DNA Registration extension.

I would guess the problem is not affected by whether you have the IsThreadSafe=true or false – but that would be worth confirming.

 

You can make a simple function that avoids the Registration rewriting but might still trigger the error.

Something like this should be close.

 

    [ExcelFunction(IsThreadSafe=false)] // try with true and false here

    public static void dnaEchoAsync(object valueToEcho, int msToSleep, ExcelAsyncHandle asyncHandle)

    {

        int managedThreadId = Thread.CurrentThread.ManagedThreadId;

        ThreadPool.QueueUserWorkItem(delegate (object state)

        {

            Thread.Sleep(msToSleep);

            int completedThreadId = Thread.CurrentThread.ManagedThreadId;

            asyncHandle.SetResult(valueToEcho + managedThreadId.ToString() + " - " + completedThreadId);

        });

    }

 

The “SetResult” call which is triggering the access violation in Excel is internally calling xlAsyncReturn | Microsoft Docs

The docs say “xlAsyncReturn is the only callback Excel allows on non-calculation threads during recalculation.”

So it should be fine from the internal threadpool thread.

 

-Govert

 

 

From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of AE
Sent: 12 January 2022 15:11
To: Excel-DNA <exce...@googlegroups.com>
Subject: [ExcelDna] Re: Addin crashes Excel after UDF

 

I placed logs everywhere in the function. The crash happens right after the value is returned. 

On Wednesday, 12 January 2022 at 16:08:19 UTC+3 AE wrote:

I have one user where addin crashes Excel every time they recalc the worksheet.

 

For example, the user selects a cell containing UDF, presses F2 and Enter. Excel crashes.

 

The UDF is marked as thread safe.

 

There is the following entry in Event Viewer:

 

 

Thanks!

 

 

--
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/9172eb6b-d999-4108-8927-e133c142d312n%40googlegroups.com.

AE

unread,
Jan 13, 2022, 2:52:17 AMJan 13
to Excel-DNA
The user has confirmed that they had other addins active in Excel which were interfering with my addin. After removing those, everything works fine. Thanks Govert!
Reply all
Reply to author
Forward
0 new messages