Search code examples
c#shadow-copy

AppDomain Shadow Copy Include referenced assemblies


I am trying Shadow Copy for the fist time. I have the following code:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {

        var sApplicationDirectory = Application.StartupPath;
        var sAppName = "propane";

        AppDomainSetup oSetup = new AppDomainSetup();
        string sApplicationFile = null;

        // Use this to ensure that if the application is running when the user performs the update, that we don't run into file locking issues.
        oSetup.ShadowCopyFiles = "true";
        oSetup.ApplicationName = "MyApplication";

        // Generate the name of the DLL we are going to launch
        sApplicationFile = System.IO.Path.Combine(sApplicationDirectory, sAppName + ".exe");

        oSetup.ApplicationBase = sApplicationDirectory;
        oSetup.ConfigurationFile = sApplicationFile + ".config";
        oSetup.LoaderOptimization = LoaderOptimization.MultiDomain;

        // Launch the application
        AppDomain oAppDomain = AppDomain.CreateDomain(sAppName, AppDomain.CurrentDomain.Evidence, oSetup);
        oAppDomain.SetData("App", sAppName);
        oAppDomain.ExecuteAssembly(sApplicationFile);

        // When the launched application closes, close this application as well
        Application.Exit();

        //Application.EnableVisualStyles();
        //Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());
    }
}

The executable is reaching the temp directory just fine and its running until I reach a referenced dll. The 14-16 dlls that I have referenced throughout the project are not being copied to this temp directory causing the app to blow up.

What am I missing? How do I get them all to get copied to the temp directory as well?


Solution

  • We have virtually the same code in our app and it works well.

    The only difference is that our main method is also decorated with

    [LoaderOptimization(LoaderOptimization.MultiDomain)]
    

    You might try that to see if it makes a difference.