VSIX: AppDomain CreateInstanceAndUnwrapError
Я создал 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);
}