Click here to Skip to main content
11,409,801 members (61,933 online)
Click here to Skip to main content

Shadow Copying of Applications

, 16 Oct 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Shadow copied applications aren't locked by the loader, so they can be updated/substituted at runtime.


Running an application shadow copied can be useful for purposes like auto-updating. On normal execution, the assembly gets locked by the loader and can't be substituted while it's executed. On shadow copying, all assemblies referenced are copied to a cache path, and loaded/executed from this location - so the assemblies aren't locked, and can be changed.


This technique is well known in ASP.NET, but on the application side, there's little information (even on MSDN). Therefore, I'd like to share my findings.

Using the Code

For executing an assembly from the cache path, we have to use a loader/bootstrapper. This little program creates a domain from which the application gets loaded. That means, when we want to start the application, we have to start the loader that loads the application for us.

The code for the application and all the referenced assemblies need no change.

The code for the loader is:

using System;
using System.IO;

namespace Loader
    static class Program
        static void Main()
            /* Enable shadow copying */

            // Get the startup path. Both assemblies (Loader and
            // MyApplication) reside in the same directory:
            string startupPath = Path.GetDirectoryName(

            // cache path = directory where the assemblies get
            // (shadow) copied:
            string cachePath = Path.Combine(
            string configFile = Path.Combine(
            string assembly = Path.Combine(

            // Create the setup for the new domain:
            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationName = "MyApplication";
            setup.ShadowCopyFiles = "true"; // note: it isn't a bool
            setup.CachePath = cachePath;
            setup.ConfigurationFile = configFile;

            // Create the application domain. The evidence of this
            // running assembly is used for the new domain:
            AppDomain domain = AppDomain.CreateDomain(

            // Start MyApplication by executing the assembly:

            // After the MyApplication has finished clean up:
            Directory.Delete(cachePath, true);

Points of Interest

This simple program gives us the possibility to easily create auto updates (that replace the application's assembly).


  • 07 October 2008 - Initial release
  • 14 October 2008 - Article updated


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Günther M. FOIDL
Software Developer (Senior) Foidl Günther
Austria Austria
Engineer in combustion engine development.
Programming languages: C#, FORTRAN 95, Matlab

FIS-overall worldcup winner in Speedski (Downhill) 2008/09 and 2009/10.

Comments and Discussions

Questionwould application take the quick reference of new change after shadow copy ? PinmemberRameshJangir27-Nov-14 3:25 
GeneralMy vote of 5 PinmemberSimon Raffl20-May-13 8:22 
GeneralMy vote of 5 PinmemberRahul Rajat Singh26-Nov-12 21:13 
QuestionRequires Admin Permissions PinmemberJeff Bowman18-Jun-12 14:29 
GeneralMy vote of 5 Pinmembermanoj kumar choubey26-Feb-12 22:33 
QuestionUser priviliges? PinmemberTobiasP15-Oct-08 4:08 
AnswerRe: User priviliges? PinmemberGünther M. FOIDL15-Oct-08 4:48 
Thanks for your reply!

First of all you can determine the path of the shadow copies. Therefore it isn't necessary to have the shadow copies in the program files folder (or a subfolder of that). You could choose a directory in the user settings.

I haven't used Vista so far - I can't say what would happen. If this is a problem choose an appropriate folder for the shadow copies.

Regarding your question about uninstalling:
As far I know the uninstallers handle the files by their name and so this shouldn't be an issue - so long the names remain the same.

GeneralRe: User priviliges? PinmemberEd.Poore16-Oct-08 12:44 
GeneralRe: User priviliges? PinmemberGünther M. FOIDL16-Oct-08 13:07 
GeneralRe: User priviliges? PinmemberEd.Poore16-Oct-08 13:14 
GeneralEnvironment.CurrentDirectory is wrong... PinmemberDanilo Corallo10-Oct-08 3:01 
GeneralRe: Environment.CurrentDirectory is wrong... PinmemberGünther M. FOIDL10-Oct-08 3:24 
GeneralRe: Environment.CurrentDirectory is wrong... PinmemberDanilo Corallo10-Oct-08 3:33 
GeneralRe: Environment.CurrentDirectory is wrong... PinmemberGünther M. FOIDL10-Oct-08 4:06 
GeneralRe: Environment.CurrentDirectory is wrong... Pinmembernicorac13-Oct-08 21:38 
AnswerRe: Environment.CurrentDirectory is wrong... PinmemberGünther M. FOIDL13-Oct-08 22:43 
GeneralRe: Environment.CurrentDirectory is wrong... Pinmembernicorac14-Oct-08 4:21 
GeneralRe: Environment.CurrentDirectory is wrong... [modified] PinmemberGünther M. FOIDL14-Oct-08 7:37 
GeneralRe: Environment.CurrentDirectory is wrong... PinmemberSkylinc14-Oct-08 19:52 
GeneralRe: Environment.CurrentDirectory is wrong... PinmemberGünther M. FOIDL14-Oct-08 22:18 
GeneralOn deleting... Pinmemberpikipoki9-Oct-08 5:24 
GeneralRe: On deleting... PinmemberGünther M. FOIDL9-Oct-08 5:44 
GeneralRe: On deleting... Pinmemberdejanstanic9-Oct-08 9:08 
GeneralMultiple instances and updating multiple files PinmemberTobiasP18-Oct-08 1:26 
GeneralRe: Multiple instances and updating multiple files PinmemberGünther M. FOIDL18-Oct-08 3:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.5 | Last Updated 16 Oct 2008
Article Copyright 2008 by Günther M. FOIDL
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid