I tried to unload my app domain but my app stopped working

I created a new app domain and loaded my assembly into it.

Assembly assembly = dom.Load("bookOne");

      

Everything was going well. the app was using a resource dictionary, etc., but when I tried to unload the dll to free memory with this code, my app exits without any errors or warnings:

try
{
    AppDomain.Unload(dom);
}
catch (CannotUnloadAppDomainException)
{
    Console.WriteLine("Book Unloaded!" + " 4");
    AppDomain.Unload(dom);
    GC.Collect();
}

      

The output window shows them after a sudden exit:

The first random exception of type "System.AppDomainUnloadedException" occurred in mscorlib.dll The first accidental exception of type "System.AppDomainUnloadedException" occurred in mscorlib.dll. thread 'vshost.RunParkingWindow' (0x1df8) exited with code 0 (0x0). Stream '' (0xfcc) exited with code 0 (0x0).

+3


source to share


1 answer


First accidental exception of type "System.AppDomainUnloadedException" occurred in mscorlib.dll

If you get AppDomainUnloadedException, you can ignore it because AppDomainUnloadedException is thrown when the app domain is unloaded, which is what you want.



From msdn

The exception thrown when trying to access an unloaded application domain

+3


source







All Articles