2

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?

Jason Down
  • 21,731
  • 12
  • 83
  • 117
ErocM
  • 4,505
  • 24
  • 94
  • 161

1 Answers1

1

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.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • I added this and it didn't copy over the references. Does it for you? – ErocM Dec 14 '11 at 21:35
  • Actually this would have been covered with this line: oSetup.LoaderOptimization = LoaderOptimization.MultiDomain; – ErocM Dec 14 '11 at 21:45
  • This does only affect sharing of assemblies across appdomains to prevent JITing the same code again. It is more relevant with NGen images which can be shared accross processes and appdomains which allows you to share the same compiled code accross processes without wasting physical memory for duplicat copies of the same thing. – Alois Kraus Dec 14 '11 at 22:02