Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provide the ability to "hot swap" / change assemblies at runtime without re-starting a process

ASP.Net allows you to copy new assemblies into the bin directory of an application without needing to re-start any services or processes.

I have an application that loads user defined plugins and extensions (some of them are COM based) - I'd like to provide similar functionality (i.e. the ability to change / update an assembly without needing to re-start the process). Currently the assembly is locked until the process is stopped.

How does ASP.Net manage this?

like image 595
Justin Avatar asked Oct 18 '10 03:10

Justin


1 Answers

ASP.Net achieves this by using "Shadow Copying". See here: MSDN Shadow Copying

Basically the assemblies are copied to a different folder by ASP.Net from which they are loaded into an App Domain. It is this copied version of the assembly that is locked by the process leaving the original assembly file (in the Bin folder) unlocked. The App Domain is then configured to monitor the original assembly for changes and in the case that an update is detected a new App Domain is created and the new assembly loaded into it.

At this point, any future requests to the web application are routed by ASP.Net to the new App Domain while the old App Domain is kept alive to continue serving any currently executing requests through to completion. When ASP.Net determines that the old App Domain is no longer handling any requests it is unloaded and the "hot swap" is complete.

From your brief description though I would recommend looking into Microsoft MEF. MEF is a framework dedicated to building the kind of plugin architectures you are describing.

like image 66
John Avatar answered Oct 31 '22 18:10

John