0

We have an application that consists of a light weight Launcher while most of the functionality is in a dll. The Launcher regularly check for updates and download a new dll if there is one. The new dll is started using code like this (MsqApplication is a dynamic):

MsqAssembly = Assembly.LoadFile("path/msq.dll"));
MsqApplication = 
Activator.CreateInstance(MsqAssembly.GetType("Msq.Program"));
MsqApplication.Start();

It works fine except the that we don´t know how to kill the old dll when a new one is started. Is there any good way to do that?

Zadrith
  • 11
  • 2
  • Load it in a new appdomain? – Wai Ha Lee Nov 08 '17 at 14:54
  • You have to load the dll into its own AppDomain, because you cannot unload assemblies, but only AppDomains. – Oliver Nov 08 '17 at 14:54
  • While you *can* use an AppDomain, if your platform supports them (.NET Core does not, for example), even with AppDomains, managing such things with full isolation is hard (you must ensure no instances "bleed over" into your main AppDomain). Furthermore, if the DLL wraps unmanaged code, even unloading the AppDomain will not properly reclaim resources. Consider using a child process, or restarting the launcher (you can spawn a small helper process to do the restart, which could be the launcher itself with different arguments). – Jeroen Mostert Nov 08 '17 at 14:58
  • They're right, however doing this and not unintentionally loading the dll in the executing appdomain is very hard to do. You have to understand exactly what's going on. Get to buying books that cover the subject. –  Nov 08 '17 at 14:58

0 Answers0