What is a good way of loading and unloading an assembly at runtime?
im making a system that should be able to load an assembly, run code from it, and then be able to unload it.
currently im using AssemblyLoadContext, however that requires all references to be destroyed before it can unload.
is there a better way of loading it? and if not, how do i completely destroy a reference to an object given i am 100% sure i have just one place where i have the instance?
8 Replies
i see, but such static generic classes will only be a thing once they are called, am i right?
someone told me recently that there was a newer better way to load assemblies at runtime than AssemblyLoadContext, however they couldnt tell me more than that they knew a new way existed, perhaps you know guess ill have to search further
thanks for your time
What's wrong with an assembly load context, they support unloading. Though to the point @univershal SyncRооt makes, there could be some potential problems with unloading.
ALCs are the new way. That's your only option in modern dotnet
What is ALC?
AssemblyLoadContext, as was mentioned in the op
Ah, thanks a lot
i see, how would i go about actually unloading assemblies loaded in one then?
someAssemblyLoadContext.Unload();
https://learn.microsoft.com/en-us/dotnet/standard/assembly/unloadability