Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a dll without stopping the service

I would like to update a dll for a server process without stopping the service. How do I do that? A bit like how asp.net automatically picks up new dlls placed in the bin folder.

like image 675
Matt Avatar asked Oct 22 '08 16:10

Matt


Video Answer


1 Answers

Asp.Net uses a technique called shadow copy

If you copy an updated dll into an application’s bin subdirectory, the ASP.NET runtime recognizes there is new code to execute. Since ASP.NET cannot swap the dll into the existing AppDomain , it starts a new AppDomain. The old application domain is “drain stopped”, that is, existing requests are allowed to finish executing, and once they are all finished the AppDomain can unload. The new AppDomain starts with the new code and begins taking all new requests.

Typically, when a dll loads into a process, the process locks the dll and you cannot overwrite the file on disk. However, AppDomains have a feature known as Shadow Copy that allows assemblies to remain unlocked and replaceable on disk.

The runtime initializes ASP.NET with Shadow Copy enabled for the bin directory. The AppDomain will copy any dll it needs from the bin directory to a temporary location before locking and loading the dll into memory. Shadow Copy allows us to overwrite any dll in the bin directory during an update without taking the web application offline.

like image 112
Gulzar Nazim Avatar answered Sep 27 '22 23:09

Gulzar Nazim