M
Mr 071
I am trying to use shadow copying provided by the framework, but I am not
able to get it to work. More specifically, after a new app domain is created
and the assembly loaded in it, it is still not possible to replace the
original DLL although it has been shadow copied to the cache folder. I need
to be able to replace plug-in DLLs while the server is running. I guess that
is what shadow copying exists for, but the DLL is locked until the app
domain has been unloaded (which fully beats the purpose of this "exercise").
Furthermore, if I comment out the line that adds the 'bin' folder to current
domain's list of private paths the assembly is not found at all, although
the new domain I am trying to load it in has its privatebinpath set to
include the 'bin' folder. Weird.
Someone please enlighten me. Thanks.
Code:
//----------------------------------------------------
cut --------------------------------------------
using System;
using System.IO;
using System.Reflection;
using System.Security.Policy;
namespace Test
{
class shadowCopying
{
public static void Main()
{
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase =
"d:\\development\\c#\\test\\shadowCopying\\";
setup.ApplicationName = "ShadowCopy";
setup.PrivateBinPath = setup.ApplicationBase + "bin";
setup.ShadowCopyDirectories = setup.ApplicationBase + "bin";
setup.ShadowCopyFiles = "true";
AppDomain.CurrentDomain.AppendPrivatePath("bin");
Evidence evidence = new
Evidence(AppDomain.CurrentDomain.Evidence);
AppDomain domain = AppDomain.CreateDomain("DynamicLoad",
evidence, setup);
string cachePath = domain.BaseDirectory + "cache";
DirectoryInfo dir = new DirectoryInfo(cachePath);
if(dir.Exists)
dir.Delete(true);
domain.SetCachePath(cachePath);
Assembly assembly = domain.Load("dynamicLoad");
Console.WriteLine("Waiting for any key....");
Console.ReadLine();
}
}
}
//---------------------------------------------
cut --------------------------------------------------
able to get it to work. More specifically, after a new app domain is created
and the assembly loaded in it, it is still not possible to replace the
original DLL although it has been shadow copied to the cache folder. I need
to be able to replace plug-in DLLs while the server is running. I guess that
is what shadow copying exists for, but the DLL is locked until the app
domain has been unloaded (which fully beats the purpose of this "exercise").
Furthermore, if I comment out the line that adds the 'bin' folder to current
domain's list of private paths the assembly is not found at all, although
the new domain I am trying to load it in has its privatebinpath set to
include the 'bin' folder. Weird.
Someone please enlighten me. Thanks.
Code:
//----------------------------------------------------
cut --------------------------------------------
using System;
using System.IO;
using System.Reflection;
using System.Security.Policy;
namespace Test
{
class shadowCopying
{
public static void Main()
{
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase =
"d:\\development\\c#\\test\\shadowCopying\\";
setup.ApplicationName = "ShadowCopy";
setup.PrivateBinPath = setup.ApplicationBase + "bin";
setup.ShadowCopyDirectories = setup.ApplicationBase + "bin";
setup.ShadowCopyFiles = "true";
AppDomain.CurrentDomain.AppendPrivatePath("bin");
Evidence evidence = new
Evidence(AppDomain.CurrentDomain.Evidence);
AppDomain domain = AppDomain.CreateDomain("DynamicLoad",
evidence, setup);
string cachePath = domain.BaseDirectory + "cache";
DirectoryInfo dir = new DirectoryInfo(cachePath);
if(dir.Exists)
dir.Delete(true);
domain.SetCachePath(cachePath);
Assembly assembly = domain.Load("dynamicLoad");
Console.WriteLine("Waiting for any key....");
Console.ReadLine();
}
}
}
//---------------------------------------------
cut --------------------------------------------------