I don't understand why in this situation context is not unload
class Program
{
static void Main(string[] args)
{
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
Assembly assembly = context.LoadFromAssemblyPath(@"C:\Users\Greedy\source\repos\ConsoleApp1\MyApp\bin\Debug\netcoreapp3.1\MyApp.dll");
context.Unload();
GC.Collect();
GC.WaitForPendingFinalizers();
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
Console.WriteLine(asm.GetName().Name);
Console.Read();
}
But now context context is successfully unloaded.
class Program
{
static void Main(string[] args)
{
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
Load(context);
context.Unload();
GC.Collect();
GC.WaitForPendingFinalizers();
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
Console.WriteLine(asm.GetName().Name);
Console.Read();
}
static void Load(CustomAssemblyLoadContext context)
{
Assembly assembly = context.LoadFromAssemblyPath(@"C:\Users\Greedy\source\repos\ConsoleApp1\MyApp\bin\Debug\netcoreapp3.1\MyApp.dll");
}
Why? and how i can fix unload in first example?