0

我已经创建了 AppDomainSetup 并应用于控制台项目,它工作正常。但是当我用 VSIX 应用它时,它不起作用,我不知道为什么。你能不能有人调查一下并帮助我摆脱它。

public class Proxy : MarshalByRefObject
{
    public Proxy()
    {
    }

    public Type[] GetTypes(string assemblyName)
    {
        var assembly = Assembly.LoadFile(assemblyName);
        return assembly.GetExportedTypes();
    }
}

VSIX MenuItemCallback 上的代码

private void MenuItemCallback(object sender, EventArgs e)
{
    string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
    string title = "ProxyCommand";

    var cachePath = Path.Combine(@"D:\Temp", "ShadowCopyCache");
    var pluginPath = Path.Combine(@"D:\Temp", "Plugins");
    if (!Directory.Exists(cachePath))
    {
        Directory.CreateDirectory(cachePath);
    }

    if (!Directory.Exists(pluginPath))
    {
        Directory.CreateDirectory(pluginPath);
    }
    var setup = new AppDomainSetup
    {
        CachePath = cachePath,
        ShadowCopyFiles = "true",
        ShadowCopyDirectories = pluginPath
    };

    domain = AppDomain.CreateDomain("MyDomain", AppDomain.CurrentDomain.Evidence, setup);

    domain = AppDomain.CreateDomain("MyDomain", AppDomain.CurrentDomain.Evidence, setup);
    var proxy = (Proxy)domain.CreateInstanceAndUnwrap(typeof(Proxy).Assembly.FullName, typeof(Proxy).FullName);
    var types = proxy.GetTypes("TestAssembly");           
    AppDomain.Unload(domain);
}
4

0 回答 0