To achieve this, IIS uses something called a shadow copy. You can implement something similar for your host. Basically, the idea is that before starting the service, you copy .DLL to another location and load your service class from this copy. The host then installs a file system monitor to listen for changes to the source file. If it discovers one, it stops the service, copies the new file, and restarts.
EDIT
(1) To start ServiceHost using a class in a library of a certain type, you will need to use reflection. Something like the following:
Assembly myAssembly = Assembly.LoadFile(path); Type serviceType = myAssembly.GetType(className); ServiceHost serviceHost = new ServiceHost(serviceType);
The documentation does not show how LoadFile resolves dependencies. You may need to hook up the Assembly.ModuleResolve event to make this work.
(2) File system monitors are likely to incur some overhead, but in my experience they are minimal. In any case, this is really your only option if you do not want to go with the installer for the updated DLLs.
(3) I do not know why your file is locked. You will have to fix this problem yourself.
source share