Skip to content

When referencing another project that has excel functions >=16 arguments, "a non-collectible assembly may not reference a collectible assembly." error is thrown #817

@speksen-kb01

Description

@speksen-kb01

Hello,

Reference project here. I stripped down everything and am using barebones excel-dna:
https://github.com/speksen-kb01/exceldna-minimal-noncollectible-assembly-error

The problem

I am referencing another project in my addin project, and in the referenced project there is an Enum. I have defined two functions that takes this enum as an argument. In the first case, there are less than 16 arguments for a function and it is successfully registered. However when the argument count goes over 16+, I am encountering the "a non-collectible assembly may not reference a collectible assembly" error.

What I am trying to do

I am trying to make a self-updating addin, following this stackoverflow answer:
https://stackoverflow.com/a/30377635
This registration error is caused by .dna file in my project, where I have referenced my other project as an external reference. If you delete this line, everything works and registration is working file as well. This however, locks the dll file, which makes me unable to update this dll file.

What I tried

Using DisableAssemblyContextUnload="true"

This actually makes all the assemblies collectible so there are no non-collectible assemblies generated, this solves the issue. However, it breaks the auto-update. After the dlls are updated, you need to reload your xll file to make your changes applied:

dynamic app = ExcelDnaUtil.Application;
app.RegisterXLL(ExcelDnaUtil.XllPath);

Then RegisterXLL throws this:
Exception thrown: 'System.InvalidOperationException' in Microsoft.CSharp.dll: 'Cannot unload non-collectible AssemblyLoadContext.'

Replacing the references with primitive types

Another solution is to replace Enum type with a string type, and parse it inside the function. This totally works and have no issues, even if you have more than 16+ arguments as long as you don't reference another class or enum for those arguments. Although I'd like to have the option to give out [ExcelHandle]s to my functions, by creating an excel function CreateModelX and returning a handle X from it. I'd have to parse my class from a string or some primitive object[,] otherwise.

Is there any way I can have all these features and not give up on any one of them? I don't really want to disable hot reloading since it is really convinient for the user

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions