So when I create a new app domain, specifying PrivateBinPath doesn't seem to be working correctly. I know that it has to be a subfolder of application base. Here's the example:
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;
}
}
So as you can see, I'm loading assembly in Proxy on new app domain, and the loaded assembly "Plugin". Now, whenever PluginRun is invoked, I get an exception FileNotFound, because it's searching for Plugin assembly in base path, yet it's in Plugins folder.
So even if specifying PrivateBinPath to PLugins folder, it doesn't seem to be able to find it.
I used Binding Log Viewer and private path is NULL, just a note.
Any solution to this issue? Thanks
Aucun commentaire:
Enregistrer un commentaire