Multi-threading issues with running ExcelDNA functions in Excel 365 for Windows

221 views
Skip to first unread message

clift...@gmail.com

unread,
Sep 20, 2023, 8:56:13 PM9/20/23
to Excel-DNA
Hi,

I have been working with Microsoft on a very peculiar issue when I am trying to run some thread safe Excel DNA UDF's on this new version of Excel https://learn.microsoft.com/en-us/officeupdates/semi-annual-enterprise-channel#version-2302-august-08. This is the specific version we are testing with and the issue has existed in all the version prior. We have never experienced this in Excel 2016.

When I run a sheet that is dependent on a number of UDF's marked thread safe, 1 out of say 6 tries (6 different instances) will have an error #VALUE! on some UDF. But as soon as I change the Excel option to single threaded, then the UDF will evaluate fine.

I tried to step through the code in the debug build of ExcelDNA and it returns a code of 16 instead of 0 when this happens in https://github.com/Excel-DNA/ExcelDna/blob/master/Source/ExcelDna.Loader/XlCallImpl.cs

            // Special kind of ObjectArrayMarshaler for the parameters (rank 1)
            using (XlMarshalXlOperArrayContext paramMarshaler
                        = new XlMarshalXlOperArrayContext(1, true))
            {
                XlOper12** ppOperParameters = (XlOper12**)paramMarshaler.ObjectArrayReturn(parameters);
                xlReturn = Excel12v(xlFunction, parameters.Length, ppOperParameters, pResultOper);
            }
But the actual C# implementation of the UDF is never hit.

How can I check whether it's something due to ExcelDNA or some internal Microsoft bug ? 


Govert van Drimmelen

unread,
Sep 21, 2023, 1:45:38 AM9/21/23
to exce...@googlegroups.com

Hi Clifton,

 

What is the simplest function that will reproduce this issue – something I can try myself?

 

From there, I would try to reproduce the issue with a native code C add-in, where Excel-DNA is not involved at all.

 

-Govert

--
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/c71792f9-73ec-42ec-98a4-371b6a00091fn%40googlegroups.com.

clift...@gmail.com

unread,
Sep 21, 2023, 1:04:55 PM9/21/23
to Excel-DNA
Hi Govert,

Thanks for the quick response. From my experience and what I have heard from our users, this behavior has been observed on UDF's implemented either in ExcelDNA and XLL+ from Planatech, both C# based solutions. And the addin's that have been implemented in C++/C XLL SDK have not had this issue.

I am trying to get this implemented using XLL+ and see if I can reproduce it. I will also try to simplify it and send it your ways. Since we also have some C++ framework to generate Excel UDF's purely from a C++ header declaration, I am also going to try the same. 

I  was hoping the ExcelDNA community has seen this behavior other than myself. The current implementation is something I have been sharing with Microsoft where we have an object id created from an object repo. We tend to have object representation of the Excel ranges into either a C# data table or in-memory sqlite and provide utility methods (UDF's) taking that object handle in Excel.

Regards,
Cliff

Govert van Drimmelen

unread,
Sep 21, 2023, 2:20:07 PM9/21/23
to exce...@googlegroups.com

Hi Cliff,

 

Thank you for the extra background.

It would be very useful to have a simple function(s) in Excel-DNA / C# that reproduces the problem.

I can’t recall hearing of anything like this problem before.

 

The object handler sounds fine, but I would suggest trying to narrow down the complexity needed to produce the error as much as possible.

Reply all
Reply to author
Forward
0 new messages