Revit 2025+ Assembly load context unload fix #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @chuongmep
Purpose
This PR fixes the issue of
AssemblyLoadContextunloading.To reproduce the issue on the
devbranch create a simple sample project with zero dependencies, except Revit:On second and run it will show that there are 2 assemblies loaded.
Seems .Net is smart enough and does some kind of unloading even if I wrap this in another project like:
However, in more sophisticated case it could increase the number each run
Description
If you debug
RevitAddinManageryou'll see the issue that after the cyclealcWeakRef.IsAliveis stilltruebecause of the following things:_activeEc = externalCommandstreamandsymbolStreamwhere not closed and disposed before unloading the contextSo
_activeEcany more in that method. It's a bit strange, that field is used in getter/setter of theActiveECproperty, but this property is not used anywhere. Probably, it can be removed, however, I've left it intact, maybe you have some plans on thatusing varfinallynot to duplicate the code.GC.Collectin a cycle invoked defferedAdditionally:
AppDomain.CurrentDomain.AssemblyResolvesubscription wrapped into a conditional compilation#if, it's redundant in R25 / R26AssemblyLoadContexthas it's name nowDeclarations
Check these if you believe they are true
*.resxfilesReviewers
IDK, @chuongmep , probably?
I'll be absent since tomorrow evening till Feb 09, feel free to change anything and merge, don't wait for me if it's in general okay for you, but you want to change style or something like that 😊
FYIs
(FILL ME IN, Optional) Names of anyone else you wish to be notified of