10k limit for the registeredMethods list in RegisterXlMethod function in XlRegistration.cs in ExcelDna.Loader

53 views
Skip to first unread message

Wenhao

unread,
May 2, 2023, 1:57:40 PM5/2/23
to Excel-DNA
Hi Everyone:

Does anyone aware of this limitation and know the reason behind it? Basically, if you login to a server which contains 2000 functions, on the 6th login, the list will stop adding members to itself and you would get this error "Logger.Registration.Info("Repeated function name: '{0}' - previous registration will be overwritten. ", CS_0024_003C_003E8__locals0.registerParameters[3]);"

Can this limit be defined/changed by user? 

Also, is there a reason that existing functions are not prevented from being added to this registeredMethods list? Instead, it just logs a line, see code below: The try would always be executed even when the function exists in the list already, which contributes to reaching the 10k limit of the list as well

Im new to C#, am i missing anything? Is there a way to do repetition registration control?  

if (registrationInfo.Exists((Predicate<object[]>)((object[] ri) => ((string)ri[3]).Equals((string)CS_0024_003C_003E8__locals0.registerParameters[3], (StringComparison)5))))
{
if (mi.SuppressOverwriteError)
{
Logger.Registration.Info("Repeated function name: '{0}' - previous registration will be overwritten. ", CS_0024_003C_003E8__locals0.registerParameters[3]);
}
else
{
Logger.Registration.Error("Repeated function name: '{0}' - previous registration will be overwritten. ", CS_0024_003C_003E8__locals0.registerParameters[3]);
}
}
try
{
XlCallImpl.TryExcelImpl(XlCallImpl.xlfRegister, out object result, CS_0024_003C_003E8__locals0.registerParameters);
Logger.Registration.Info("Register - XllPath={0}, ProcName={1}, FunctionType={2}, Name={3} - Result={4}", CS_0024_003C_003E8__locals0.registerParameters[0], CS_0024_003C_003E8__locals0.registerParameters[1], CS_0024_003C_003E8__locals0.registerParameters[2], CS_0024_003C_003E8__locals0.registerParameters[3], result);
if (result is double)
{
mi.RegisterId = (double)result;
registeredMethods.Add(mi);
if (mi.IsCommand)
{
RegisterMenu(mi);
RegisterShortCut(mi);
}
}


my version info:
<package id="ExcelDna.AddIn" version="1.1.1" targetFramework="net461" developmentDependency="true" />
  <package id="ExcelDna.Integration" version="1.1.0" targetFramework="net461" />
  <package id="ExcelDna.Interop" version="14.0.1" targetFramework="net461" />

Thank you very much in advance!!

Wenhao


Govert van Drimmelen

unread,
May 2, 2023, 2:59:07 PM5/2/23
to exce...@googlegroups.com

Hi Wenhao,

 

You don’t have to look at the decompiled code – the Excel-DNA project is open source and here on GitHub: Excel-DNA/ExcelDna: Excel-DNA - Free and easy .NET for Excel. This repository contains the core Excel-DNA library. (github.com)

 

The 10,000 function limitation is built into the native part of the library, so not easy to change for the user. But it is not an Excel limitation, even though registering a large number of functions in Excel can become slow.

 

The plumbing in Excel-DNA that links the managed .NET function to native code does not currently support changing or overwriting the link between the registered function and the native export. So additional registrations are always added to the end, and if you keep calling the registration you will eventually run out of slots.

 

If you are planning to re-register functions in your add-in, for example based on a web service, then I suggest adding some tracking inside your add-in of what functions you have registered, and not registering the same functions again.

 

Alternatively, you can make a design where you load a new add-in when the registrations have to be re-done. But unloading and reloading of add-ins can also be problematic, and unloading is not supported under .NET 6, so that might not be a perfect solution for you either.

 

-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/eb8fa093-6188-4000-93ae-b9a6af3bbe50n%40googlegroups.com.

Wenhao

unread,
May 2, 2023, 4:14:12 PM5/2/23
to Excel-DNA
wow thanks Govert for the fast reply! Very Impressive!
I used the compiled code cuz I had to debug into it from my project.

Interestingly my plan was to add a map into my addin to control the repetitive registration, one caveat that I could think of right now is that when user login to different servers with my addin (single session design atm), it unregisters the functions from the prev session first and then registers the new function from the new server, however, the unregistration doesnt clear registeredMethods list even though it clears function wizard. 
Do you have any suggestions on how to clear/remove items from  registeredMethods list accordingly? 

Thanks again!
Wenhao

Wenhao

unread,
May 9, 2023, 12:38:50 PM5/9/23
to Excel-DNA
Hi Govert,

With limit, as you said, i'm trying to keep a track on my side. But is there a good way to just make the registered method from server1 as hidden in the function wizard when logged in to server2 and bring them back to the function wizard when server 1 is re-logged in? 

Basically: (login to different servers)
serv1: 1700 functions, register them

serv2: 500 functions, make 1700 functions from server 1 hidden from the function wizard, register 500
 
serv3: 200 functions,  make 500 functions from server 2 hidden from the function wizard, register 200

serv1: 1700 functions previously registered from the first login to this server, put 1700 functions back to Function wizard, make the 200 functions from server 3 hidden from the function wizard

server3:  200 functions previously registered from the first login to this server, put 200 functions back to Function wizard,  make 1700 functions from server 1 hidden from the function wizard

Thanks,
Wenhao
On Tuesday, May 2, 2023 at 2:59:07 PM UTC-4 Govert van Drimmelen wrote:
Reply all
Reply to author
Forward
0 new messages