0

i'm new in appdomain concept. It stated here that shadow copy creates a copy of the assembly you are referencing but when I check my ShadowCopyDirectories, it is empty.

Here's my code:

        AppDomainSetup sandboxDomainSetup = new AppDomainSetup();
        sandboxDomainSetup.ApplicationBase = @"D:\Testing\AppDomainTestProject\MainUI\bin\Debug";
        sandboxDomainSetup.ShadowCopyFiles = "true";
        string appData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
        string tempfolder = Path.Combine(appData, "TestAppDomain"); //C:\ProgramData\TestAppDomain
        if (!Directory.Exists(tempfolder))
        {
            Directory.CreateDirectory(tempfolder);
        }
        sandboxDomainSetup.ShadowCopyDirectories = tempfolder;

        sandbox = AppDomain.CreateDomain("MyAppDomain", null, sandboxDomainSetup);

        Assembly sandboxAssembly = Assembly.LoadFrom(assemblyPath.ToString());
        var instance = sandbox.CreateInstance(sandboxAssembly.GetName().Name, sandboxAssembly.GetTypes().FirstOrDefault().FullName);
        if (instance != null)
        {
            object obj = instance.Unwrap();}

Did I missed out anything? Thank you

Community
  • 1
  • 1
xscape
  • 3,318
  • 9
  • 45
  • 86
  • Just in case, I hope that's not it, but after all it's a string containing a boolean : true.ToString() returns "True", and MSDN says it expects "true" ... http://msdn.microsoft.com/en-us/library/system.appdomainsetup.shadowcopyfiles.aspx – Vivien Ruiz Jul 25 '12 at 11:42
  • its still the same. change from true.ToString to "true". It's not copying. – xscape Jul 26 '12 at 02:07

1 Answers1

2

The AppDomainSetup.ShadowCopyDirectories property is to specify the directories that contain assemblies to be shadow-copied when loaded. This is not the location where assemblies will be copied. The AppDomainSetup.CachePath property is the one you are looking for. In your sample code, Shadow-Copy was enabled successfully but the loaded assemblies were copied in a temp folder created by the CLR.

Panos Rontogiannis
  • 4,154
  • 1
  • 24
  • 29