1

I'm trying to have some kind of "auto-update" application. Idea is to have unchangeable code, which will reference a DLL, with all the logic contained in DLL. Basically, it will work by looking for updates every 5 minutes. If an update is available, the dispose method is called, disposing of everything from DLL, then downloading new DLL and referencing it, also running its start method afterward.

I have something like this:

var DLL = Assembly.LoadFile(path_to_appdata+"dll_name.dll");

runner_dll = DLL.GetType("dll_namespace_name.Manager");
var c = Activator.CreateInstance(runner_dll);
var method = runner_dll.GetMethod("run_client");
method.Invoke(c, new object[] { });             

and it works. However, the thing is I can't update the DLL because it's in use. I've read that I can't remove it directly from Assembly, but I can load it in an AppDomain, then unload an AppDomain. However, I've tried to do it, but I don't seem to make it work.

Any help would be very appreciated.

Nikola Pejic
  • 145
  • 1
  • 12
  • [How to Load an Assembly to AppDomain with all references recursively?](https://stackoverflow.com/q/658498/7444103). But you may prefer an *AddIn* (extension), see [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/en-us/dotnet/framework/mef/). [MAF](https://learn.microsoft.com/en-us/dotnet/api/system.addin) is kind of gone. – Jimi Jul 18 '20 at 11:37
  • In this case, maybe multi-process is better. You can use a loader to control the update, no matter it is the GUI or service or background exe. The exes use RPC or pipe to communicate with each other. – neohope Jul 20 '20 at 04:13
  • @neohope I think that's what I'm going to do. It's too hard referencing all DLLs, but executables on the other hand, much easier. I'm gonna create a console app with all functions of DLL, run it from service, then it's gonna run in the background doing pretty much what it should. – Nikola Pejic Jul 20 '20 at 10:26

1 Answers1

0

I've found an answer to this, but it's not about referencing the DLLs. My solution right now is to bundle everything in an executable, then start it from the first app. The first app will also make sure to stop it and update when necessary.

Nikola Pejic
  • 145
  • 1
  • 12