I have an application that loads external assemblies which I have no control over (similar to a plugin model where other people create and develop assemblies that are used b
I've dealt with a similar problem in my app. Basically, you can't do anything more to force the AppDomain
to go down than Unload
does.
It basically calls abort of all threads that are executing code in the AppDomain
, and if that code is stuck in a finalizer or unmanaged code, there isn't much that can be done.
If, based on the program in question, it's likely that the finalizer/unmanaged code will finish some later time, you can absolutely call Unload
again. If not, you can either leak the domain on purpose or cycle the process.
Try to make GC.Collect() if you do not unload the domain.
try
{
AppDomain.Unload(otherAssemblyDomain);
}
catch (CannotUnloadAppDomainException)
{
GC.Collect();
AppDomain.Unload(otherAssemblyDomain);
}