W
Wal Turner
Hi there. There are various snippets on forums regarding issues with
AppDomain.Unload and how it just doesnt work.
Fortunately, I got it working with the base case, after much fiddling.
Consider this 5 line program:
AppDomain domain = AppDomain.CreateDomain("MyDomain");
domain.CreateInstance("TempDLL", "TempDLL.Class1");
MessageBox.Show("try deleting file now"); //cant delete file
AppDomain.Unload(domain);
MessageBox.Show("try again"); //can delete file
Interstingly enough, if you use domain.Load( ) instead of createInstance you
can't delete the file as per the last line! (see
http://www.dotnet247.com/247reference/msgs/10/54067.aspx)
So getting around this was the first hurdle (also remember to use the name
of the dll WITHOUT the extension)
Now the task of putting it to work in the real application!
Unfortunately it didnt work - I got the the following errors when doing
AppDomain.Unload( )
An unhandled exception of type 'System.Threading.ThreadAbortException'
occurred in Unknown Module.
Additional information: Thread was being aborted.
(note these errors came out on console, they arent handle-able) - I'm not
sure that this would even prevent the module from unloading. So I'm not
convinced that this is the one error that is stopping the module being
unloaded. I have read that there are complications doing AppDomain.Unload( )
if you use API calls but i was thinking this shouldnt matter because I am
disposing of my main class and calling GC before unloading.
Any help
Wal
AppDomain.Unload and how it just doesnt work.
Fortunately, I got it working with the base case, after much fiddling.
Consider this 5 line program:
AppDomain domain = AppDomain.CreateDomain("MyDomain");
domain.CreateInstance("TempDLL", "TempDLL.Class1");
MessageBox.Show("try deleting file now"); //cant delete file
AppDomain.Unload(domain);
MessageBox.Show("try again"); //can delete file
Interstingly enough, if you use domain.Load( ) instead of createInstance you
can't delete the file as per the last line! (see
http://www.dotnet247.com/247reference/msgs/10/54067.aspx)
So getting around this was the first hurdle (also remember to use the name
of the dll WITHOUT the extension)
Now the task of putting it to work in the real application!
Unfortunately it didnt work - I got the the following errors when doing
AppDomain.Unload( )
An unhandled exception of type 'System.Threading.ThreadAbortException'
occurred in Unknown Module.
Additional information: Thread was being aborted.
(note these errors came out on console, they arent handle-able) - I'm not
sure that this would even prevent the module from unloading. So I'm not
convinced that this is the one error that is stopping the module being
unloaded. I have read that there are complications doing AppDomain.Unload( )
if you use API calls but i was thinking this shouldnt matter because I am
disposing of my main class and calling GC before unloading.
Any help
Wal