关于AppDomain 创建实例进行程序集之间的通讯问题
各位高手们,我在用AppDomain 的CreateInstanceFromAndUnwrap 创建一个实例进行程序之间的通讯时,会抛异常,提示"Constructor on type 'DllResource.DeriveClass' not found.",代码如下:
private BaseClass GetTrigger(string FileName)//返回指定文件的TriggerDesignerFacade
{
try
{
AppDomainSetup info = new AppDomainSetup();
info.ApplicationName = "Load";
AllTriggersDomain = AppDomain.CreateDomain(FileName, null, info);
Domains.Add(FileName, AllTriggersDomain);
object[] parms = { FileName };
BindingFlags bindings = BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public;
//创建实践实现程序集之间的通讯
var Trigger = (BaseClass)AllTriggersDomain.CreateInstanceFromAndUnwrap(FileName,
"DllResource.DeriveClass", true, bindings, null, parms, null, null, null);
//Assembly aDll = Trigger.GetLoadAssembly(FileName);
//var rc = (BaseClass)aDll.CreateInstance("DllResource.DeriveClass");
//rc.SetSettingFolder(System.IO.Path.GetDirectoryName(FileName));
//return rc;
return null;
}
catch
{
return null;
}
}
我想调用抽象类进行通讯,可是创建实例时失败,在这里BaseClass 是基类(抽象类) DeriveClass 是继承类;
我把这行代码改成:
var Trigger = (BaseClass)AllTriggersDomain.CreateInstanceFromAndUnwrap(FileName,
"DllResource.BaseClass", true, bindings, null, parms, null, null, null);
也是一样提示:"Constructor on type 'DllResource.BaseClass' not found."
下面是我的继承类和基类的代码:
继承类:
namespace DllResource
{
class DeriveClass : BaseClass
{
public DeriveClass ()
{
}
public override void Display()
{
throw new NotImplementedException();
}
public override int Counter(int num)
{
return num++;
}
}
}
基础类:
namespace DllResource
{
public abstract class BaseClass
{
public abstract void Display();
public abstract int Counter(int num);
}
}
不知道怎么解决,请各位高手指点,在线等...................