'AssemblyLoadContext Will Not Unload
I have created a test application that utilizes the relatively new AssemblyLoadContext object. My issue now is that despite me doing everything I could find in the documentation. It does not unload. There isn't that much room for error, as all I am doing is loading then trying to unload.
private void FileWatcher_OnServerPluginLoaded(object sender, string e)
{
AssemblyLoadContext alc = new AssemblyLoadContext("meme", true);
WeakReference testAlcWeakRef = new WeakReference(alc);
Assembly assembly = null;
using (var fs = File.Open(e, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
assembly = alc.Default.LoadFromStream(fs);
}
assembly = null;
alc.Unload();
GC.Collect();
while (testAlcWeakRef.IsAlive)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
