Problem with re-registering addin in Excel

124 views
Skip to first unread message

Wojciech Mioduszewski

unread,
Jan 22, 2023, 4:29:13 AM1/22/23
to Excel-DNA
Hello Excel-DNA team!

Let me quickly describe my setup so my question will hopefully be more precise.

I am developing an Excel add-in through ExcelDNA with auto-updates.

As advised by your other threads I chose the unpacked approach, so I can update the *.dll libraries while Excel with the add-in is still running.

But also, as you wrote here I thought I will give it a try to auto-registering.

Since this is quite an old answer, I am using ExcelIntegration instead of Application to do so, so it's like:

ExcelIntegration.RegisterXLL(ExcelDnaUtil.XllPath);

But unfortunately, it doesn't work. I am having my Excel opened, with add-in in version 0.2. Then I am overwriting dll files so they become 0.3 in addin lib directory and run RegisterXll - my Excel closes without any message (even when there are unsaved changes in the sheet).

I also found your thread where you're pointing out I should queue it up, so I tried:

ExcelAsyncUtil.QueueAsMacro(() =>
            {
                ExcelIntegration.UnregisterXLL(ExcelDnaUtil.XllPath); // Should not need this if you are re-registering...
                ExcelIntegration.RegisterXLL(ExcelDnaUtil.XllPath);
            });


Both with and without Unregistering. An approach without unregistering just closes the Excel as in the no-macro variant. When I did debug it, the exception just before says: 
Exception of type 'ExcelDna.Integration.XlCallException' was thrown.

Putting Unregister in just before the call finally gives me some error in Excel which looks like in the screenshot attached.

The addin logger says:
ExcelDna.Integration Error: 6 : Unexpected error trying to run SyncMacro for queued macro execution. : TargetInvocationException - Exception has been thrown by the target of an invocation.

As you wrote on this StackOverflow thread, I am NOT copying ExcelIntegration into the  lib folder (however, I also tried what happens when it is actually there - with no success though).

The add-in is re-loading correctly if I am doing File->Open.. -> xll

So, my question is: am I able to register this addin automatically from the code? Do I perform any mistake in the process or that's how it is in my case?

Appreciate your thoughts on that.

Cheers,
Wojciech
ureg-reg.png

Wojciech Mioduszewski

unread,
Jan 22, 2023, 4:45:59 AM1/22/23
to Excel-DNA
Here I found the thread I had this macro queueing from: https://groups.google.com/g/exceldna/c/Ge9FvmN3PNA

Wojciech Mioduszewski

unread,
Jan 28, 2023, 4:04:01 AM1/28/23
to Excel-DNA
Hey Govert, 

have you had a chance to get through the question? Are there any chances it could work for me?
Am I doing something wrong or it could be the problem with the cpp calls themselves?

I'd be grateful for your answer.

Cheers,
Wojciech

Govert van Drimmelen

unread,
Jan 29, 2023, 5:05:37 AM1/29/23
to Excel-DNA
Hi Wojciech,

Reloading of add-in has always been a tricky story, and I'm not sure what the current status is under .NET Framework and .NET 6.
I'll start by saying that if you use any of the COM-based features, like Ribbon or CTP extensions, RTD or async functions of COM Server integration with VBA, then unloading is not likely to work.
Next, there is quite a difference between .NET Framework and >NET 6 in how the add-in isolation works (.NET Framework has much stronger isolation with AppDomains). So while we did some work to get function reloading work somewhat with .NET 6, it's not quite the same. What runtime are you targeting?)
Also, it looks like you are trying to update 'yourself' while running (with the code ExcelIntegration.RegisterXLL(ExcelDnaUtil.XllPath); ) I very much doubt whether this will work under .NET 6, since the assembly resolution will not allow the same library to be loaded from a different location into the AssemlbyLoadContext.
You might have more luck with a separate master / slave add-in configuration.

My best suggestion for managing add-in versioning is that you have a look at the Add-In Manager project here: Excel-DNA/AddInManager: The Excel-DNA Add-In Manager makes it ease to distribute, install and update Excel add-ins. (github.com)
It's not complete or documented project, but might be useful for you to look at.
The idea is to have a master add-in that in turn manages add-ins from a file or web-hosted directory and then lets you check for and load add-ins.
It's somewhat of a work in progress, so if you try it, andy feedback would be welcome.

Overall, I'm sorry I don't have easy answers for this problem.

-Govert

Wojciech Mioduszewski

unread,
Feb 11, 2023, 7:08:44 AM2/11/23
to Excel-DNA
Hey Govert,

thank you very much for your insights!

I am targeting .NET 4.8.
Yes, I am using Ribbon.
And yes, I am trying to update myself while running.

Taking the above into consideration, I think I will use the updates that demand Excel restart.
Not a big deal, I just wanted to utilize auto-update if it's available/achievable.
Thanks again for your awesome work and assistance.

Cheers,
Wojciech

Reply all
Reply to author
Forward
0 new messages