Hi Kenneth,
Thank you for reporting the problem and sending a sample project to test with easily.
I see the same error and will have to dig in a bit to see what’s going on.
Note that you should target “net6.0-windows” as the TargetFramework, not just “net6.0”.’
But this is not the cause of the issue you see with the “NotSupportedException”.
Also, there is a switch in version 1.6.0-preview4 that allows the hosting AssemblyLoadContext to not be marked as “collectible”:
<ExcelAddInDisableAssemblyContextUnload>true</ExcelAddInDisableAssemblyContextUnload>
but sadly this does not seem to change the behaviour either.
Most likely the type that fails to load is the “ExcelAsyncHandle” type in ExcelDna.Integration.
But I can’t tell which assembly in this context is “non-collectible”.
If the module being created for the dynamic wrapper function is non-collectible, then I imagine the “ExcelAddInDisableAssemblyContextUnload” flag should mean that ExcelAsyncHandle is now in a non-collectible assembly too.
So I’m not sure what is going, and it will need some more debugging.
-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/94277b08-6522-4279-8516-0b311e3c0d5cn%40googlegroups.com.
As your project uses a .dna file, instead of ExcelAddInDisableAssemblyContextUnload property, you need to add DisableAssemblyContextUnload to the .dna file like this:
<DnaLibrary Name="ProcessRegistrationTest Excel Add-In" RuntimeVersion="v4.0" DisableAssemblyContextUnload="true">
With latest ExcelDna packages:
<PackageReference Include="ExcelDna.AddIn" Version="1.6.0-preview5" />
<PackageReference Include="ExcelDna.Integration" Version="1.6.0-preview5" />
<PackageReference Include="ExcelDna.Registration" Version="1.6.0-preview5" />
It prevents the System.NotSupportedException for me.
Can you please test it on your machine?
Hi Kenneth and Sergey,
In addition to the option of running the add-in inside a “non unloadable AssemblyLoadContext” by setting the DisableAssemblyContextUnload flag, you can also wrap the problematic registration code inside a “ContextualReflectionContext” where the dynamic code will get generated in the right place.
For this your AutoOpen would becode:
public void AutoOpen()
{
using (var ctx = System.Runtime.Loader.AssemblyLoadContext.EnterContextualReflection(this.GetType().Assembly))
{
ExcelRegistration
.GetExcelFunctions()
.ProcessParamsRegistrations()
.ProcessAsyncRegistrations(nativeAsyncIfAvailable: true)
.RegisterFunctions();
}
}
So that’s a second option you can test.
-Govert
From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of Sergey Vlasov
Sent: 3 August 2022 13:44
To: Excel-DNA <exce...@googlegroups.com>
Subject: [ExcelDna] Re: Difference in async and params registration order produces different functions
Kenneth,
--
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/de5ff0bc-1287-48da-9073-6276995d8b80n%40googlegroups.com.