I am creating an uninstall utility in C#. The utility will unregistered the files registered through Regasm and then it will delete those files.
Assembly asm = Assembly.LoadFrom("c:\\Test.dll")
int count = files.Length;
RegistrationServices regAsm = new RegistrationServices();
if (regAsm.UnregisterAssembly(asm))
MessageBox.Show("Unregistered Successfully");
The above code works fine but when i try to delete Test.dll, error appear and cannot delete it.
What i have understand that Assembly.LoadFrom(“c:\Test.dll”), has save the reference to this file and it is not losing it. Is there any way to resolve this issue?
Thanks and Regards
You need to load the type in another appdomain. Typically this is done by loading a type derived from MarshalByRefObject into another domain, marshaling the instance to the original domain and executing the method via proxy. It sounds harder then it is so here is the exampe: