Switch to AssemblyLoadContext for assembly retrival #53
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.
With .NET (core) a new mechanism for assembly loading/plugin discovery has been introduced:
AssemblyLoadContext
. It allows to have multiple contexts and each can load and unload assemblies. The problem is that they are all (from all AssemblyLoadContexts) returned byAppDomain.CurrentDomain.GetAssemblies()
. This is problematic asAssemblyLoadContext.Unload()
does not immediately unload assemblies but marks them for removal by theGC. GetAssemblies()
therefore returns assemblies that might get GC'ed at a later point in time.Additionally, having the same assembly loaded multiple times breaks Attic and leads to not finding any transformers at all and as a result prevents saving/loading of files.
Therefore,
AppDomain.CurrentDomain.GetAssemblies()
is replaced withAssemblyLoadContext.Default.Assemblies
in this PR to only return the assemblies from the default context.AssemblyLoadContext.Default.Assemblies
only works with .NET, therefore the project was upgraded to .NET 8 and support for netstandard2.0 and net472 was dropped.