AppDomain shadow copying does not work (original builds are locked)

Here is a small class that I use to search for a list of available plugins:

internal static class PluginDirectoryLoader
{
    public static PluginInfo[] ListPlugins(string path)
    {
        var name = Path.GetFileName(path);
        var setup = new AppDomainSetup
        {
            ApplicationBase = path,
            ShadowCopyFiles = "true"
        };
        var appdomain = AppDomain.CreateDomain("PluginDirectoryLoader." + name, null, setup);
        var exts = (IServerExtensionDiscovery)appdomain.CreateInstanceAndUnwrap("ServerX.Common", "ServerX.Common.ServerExtensionDiscovery");
        PluginInfo[] plugins = null;
        try
        {
            plugins = exts.ListPlugins(); // <-- BREAK HERE
        }
        catch
        {
            // to do
        }
        finally
        {
            AppDomain.Unload(appdomain);
        }
        return plugins ?? new PluginInfo[0];
    }
}

The parameter pathpoints to a subdirectory containing loadable plugin assemblies. The idea is to download them using a separate AppDomain with shadow copy enabled.

In this case, shadow copy is not really necessary, since AppDomain is quickly unloaded, but when I actually load plugins in the next block of code that I intend to write, I want to use shadow copy so that binary files can be updated on the fly . I turned on shadow copying in this class as a test to make sure that I am doing this correctly.

-, , , (.. plugins = exts.ListPlugins()), !

, , , AppDomain, , ?

+3
1

. , AppDomainSetup. ShadowCopyDirectories.

var setup = new AppDomainSetup
{
    ApplicationBase = path,
    ShadowCopyFiles = "true",
    ShadowCopyDirectories = path
};

, , , AppDomain.

+3

All Articles