Error reloading add-in

170 views
Skip to first unread message

Lucas Dias

unread,
Jul 3, 2022, 12:31:00 PM7/3/22
to Excel-DNA
Hi Govert and all,

I'm running into the error below when trying to reload an already open XLL.

Error.png

I already tried to reload in 4 ways:
  1. File -> Open the .xll
  2. From VBA, Application.RegisterXLL...
  3. From another XLL addin, run ExcelAsyncUtil.QueueAsMacro ... ExcelIntegration.RegisterXLL ...
  4. Addins(...).Installed = False then Installed = True (doesn't give an error, but the functions disappear).
All lead to the same error.

Version: Fresh .NET 6 project, ExcelDNA 1.6.0-preview3, target net6.0-windows.

Any clues?
Thanks in advance!

Lucas Dias

unread,
Jul 3, 2022, 3:39:50 PM7/3/22
to Excel-DNA
I was trying a bunch of things, including the Master/Slave UnregisterXLL/RegisterXLL suggested structure in another post, but the same error appears.
When creating a .NET Framework project it works normally.

Govert van Drimmelen

unread,
Jul 3, 2022, 6:33:28 PM7/3/22
to Excel-DNA
Hi Lucas,

For the .NET 6 implementation, I've not looked at support for the unloading / reloading of add-ins yet.
It's one aspect of the host implementation that works completely differently to .NET Framework.
While we should be able to address the particular error you see, there is much more to do for unloading support at the same level of the .NET Framework side.
So I doubt we'll have much better support for v 1.6.0.

Over the long term it would be nice to extend unloading support even for the COM-based parts like the RTD server, COM server etc., which in some cases can't be unloaded currently in .NET Framework.

-Govert

Lucas Dias

unread,
Jul 3, 2022, 6:50:28 PM7/3/22
to Excel-DNA
Alright! Thanks for the quick answer. Are there any resources, besides the source code, about the ExcelDna integration with .Net 6? I'd like to contribute with this issue and others.
Thanks a lot!

Govert van Drimmelen

unread,
Jul 5, 2022, 6:31:14 AM7/5/22
to Excel-DNA
Hi Lucas,

The native code project that implements the .NET 6.0 hosting is here:  ExcelDna/Source/ExcelDna.Host at master · Excel-DNA/ExcelDna (github.com)
In particular the assertion you're running into is here: ExcelDna/host.cpp at master · Excel-DNA/ExcelDna (github.com)
There's no extra documentation about this, though the .NET 6.0 mechanism for isolation (and hopefully unloading in a future Excel-DNA version) is called the "AssemblyLoadContext").

It is a bit tricky to get to where you can build and debug the Excel-DNA host project, so you might want to get in touch with me directly before you get too frustrated, or go too far.
We'll have a bit of a look at the reloading story too, to see what the status and scope would be.

-Govert

Lucas Dias

unread,
Jul 6, 2022, 1:31:58 PM7/6/22
to Excel-DNA
OK, understood!!! Thanks a lot.

Lucas Dias

unread,
Sep 28, 2022, 4:40:22 PM9/28/22
to Excel-DNA
Hi Govert,
I'm trying to get hot-reloading to work on .NET 6 using the latest version (1.6.0-rc1), where the host.cpp problems seem to be fixed. I'm able to re-register the XLL (through drag and drop), which shows the pop-up below. However, the function body/behavior doesn't change. Is this expected?
Thanks in advance!

Sem título.png

Govert van Drimmelen

unread,
Sep 28, 2022, 6:15:50 PM9/28/22
to exce...@googlegroups.com

Hi Lucas,

 

While we fixed the worst error when reloading, we’ve not incorporated the function re-registration for version 1.6.

This would involve changing (or duplicating) the managed code that is shared by .NET Framework and .NET 6, and I wasn’t comfortable doing that at this stage – I want the .NET Framework version at runtime to be as stable for this version as possible. So the behaviour you report is ‘expected’ and the add-in reloading support is still planned for after version 1.6.

 

However, some work in this direction has been done, and you might want to rebuild and try out from the ReloadNET6 branch: Excel-DNA/ExcelDna at ReloadNET6 (github.com)

 

Otherwise you’ll have to wait a bit longer. Unfortunately under .NET 6 this whole story will be much harder, so I can’t tell whether or when we’ll have good reload support under .NET 6. Even for .NET Framework, the support is quite limited.

 

-Govert

 

 

From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of Lucas Dias
Sent: 28 September 2022 22:40
To: Excel-DNA <exce...@googlegroups.com>
Subject: [ExcelDna] Re: Error reloading add-in

 

Hi Govert,

I'm trying to get hot-reloading to work on .NET 6 using the latest version (1.6.0-rc1), where the host.cpp problems seem to be fixed. I'm able to re-register the XLL (through drag and drop), which shows the pop-up below. However, the function body/behavior doesn't change. Is this expected?

Thanks in advance!

 

 

I already tried to reload in 4 ways:

  1. File -> Open the .xll
  2. From VBA, Application.RegisterXLL...
  3. From another XLL addin, run ExcelAsyncUtil.QueueAsMacro ... ExcelIntegration.RegisterXLL ...
  4. Addins(...).Installed = False then Installed = True (doesn't give an error, but the functions disappear).

All lead to the same error.

 

Version: Fresh .NET 6 project, ExcelDNA 1.6.0-preview3, target net6.0-windows.

 

Any clues?

Thanks in advance!

--
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/0b1818a6-e748-4cad-b1ee-fb2c4f17d018n%40googlegroups.com.

image001.png

Lucas Dias

unread,
Sep 28, 2022, 7:18:07 PM9/28/22
to Excel-DNA
Alright, thanks a lot!!

Govert van Drimmelen

unread,
Oct 19, 2022, 5:39:46 AM10/19/22
to Excel-DNA
Hi Lucas,

We've made some improvement for the reloading support under .NET 6.
The changes are in version 1.6.1-alpha3.
I think functions will be re-registered, but I'm not sure about the ribbon etc.
I have not had chance to experiment with this myself, but if you can give it a try, I'd be interested in anything you find.

-Govert

Lucas Dias

unread,
Oct 19, 2022, 11:22:10 AM10/19/22
to exce...@googlegroups.com
Hi Govert,
Thanks a lot! I'll give it a try.
Best,

You received this message because you are subscribed to a topic in the Google Groups "Excel-DNA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/exceldna/zuKNQu-7q5s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/de825ebb-832e-4b51-8524-39fdb407960fn%40googlegroups.com.

Lucas Dias

unread,
Nov 8, 2022, 12:42:26 PM11/8/22
to exce...@googlegroups.com
It works Govert!! Thanks a lot!!
Best regards,

Lucas Dias

unread,
Nov 8, 2022, 5:52:57 PM11/8/22
to exce...@googlegroups.com
Hi Govert,
Upon further testing, the reloading doesn't work in more complex programs, with multiple DLLs. I suspect that there might be a locked DLL (in use) that breaks the reloading. Unfortunately no error is thrown. Is there a verbose mode that shows errors during the process so I can investigate the problem?
Thanks a lot!

Govert van Drimmelen

unread,
Nov 8, 2022, 6:54:08 PM11/8/22
to exce...@googlegroups.com

Debugging the “AssemblyLoadContext” unloading is quite a rabbit hole to go down - How to use and debug assembly unloadability in .NET | Microsoft Learn

 

I think a good start would be to make a minimal add-in that doesn’t work.

Lucas Dias

unread,
Nov 9, 2022, 7:53:45 AM11/9/22
to Excel-DNA
Hi Govert, thanks for looking into this.
Found some clues, the error happens during AutoOpen (I'm using a COM server).
After a lot of tests, the reloading stopped working even for fresh new add-ins with just 1 function. Go figure. Excel being Excel.

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Access to the registry key 'HKEY_CLASSES_ROOT\_ExcelDna_PermissionsTest_Machine' is denied.
  Source=Microsoft.Win32.Registry
  StackTrace:
   at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) in /_/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs:line 921

Govert van Drimmelen

unread,
Nov 9, 2022, 5:17:34 PM11/9/22
to exce...@googlegroups.com

That error should not be fatal – we’re just checking whether we can write to the machine hive, and the exception tells us we can’t.

In that case we’ll back down and write to the user hive.

 

Reloading when you’re using a COM Server is a hard case that we never dealt with in .NET Framework.

Reply all
Reply to author
Forward
0 new messages