因此,当我创建一个新的应用程序域时,指定PrivateBinPath似乎无法正常工作。我知道它必须是应用程序基础的子文件夹。 这是示例:
public class PluginHandler : MarshalByRefObject
{
public void Launch()
{
var domainSetup = new AppDomainSetup()
{
ApplicationBase = Util.AssemblyDirectory,
PrivateBinPath = @"Plugins"
};
appDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, domainSetup);
assemblyLoader = appDomain.CreateInstanceAndUnwrap
(Assembly.GetExecutingAssembly().FullName, typeof(AssemblyLoader).FullName) as AssemblyLoader;
thread = new Thread(() =>
assemblyLoader.LoadAssembly(PluginPath, ProxyBase, this));
thread.Start();
}
}
public class AssemblyLoader : MarshalByRefObject
{
private object pluginObj;
private MethodInfo pluginStop;
[HandleProcessCorruptedStateExceptions]
public bool LoadAssembly(string path, CoreBase proxyBase, PluginHandler pluginHandler)
{
var assembly = Assembly.Load(File.ReadAllBytes(path));
var types = assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(Core))).ToArray();
for (int i = 0; i < types.Length; i++)
{
FieldInfo coreBase = types[i].GetField
("proxyBase", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
MethodInfo pluginRun = types[i].GetMethod("PluginRun");
pluginStop = types[i].GetMethod("PluginStop");
if (pluginRun != null)
{
pluginObj = assembly.CreateInstance(types[i].FullName);
coreBase.SetValue(pluginObj, proxyBase);
pluginHandler.IsLoaded = true;
pluginHandler.CorePlugin = pluginObj;
if (!proxyBase.LaunchedPlugins.Contains(pluginHandler))
{
proxyBase.LaunchedPlugins.Add(pluginHandler);
}
pluginRun.Invoke(pluginObj, null);
return true;
}
}
return false;
}
}
如您所见,我正在新应用程序域的Proxy中加载程序集,并加载了程序集“ Plugin”。现在,每当调用PluginRun时,我都会得到一个FileNotFound异常,因为它在基本路径中搜索插件程序集,但它在Plugins文件夹中。
因此,即使在PLugins文件夹中指定PrivateBinPath,它似乎也找不到。
我使用了Binding Log Viewer,私有路径为NULL,只是一个注释。
任何解决此问题的方法?谢谢