|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册
x
大虾们,有一个问题
.dll(iGenDLL.GenDLL)中定义类中包含事件:
public delegate void TestOne(object sender, string strPar1, string strPar2);
public event TestOne TestOneEvent;
然后使用后期绑定方式调用.dll
// Load assembly from dll file
Assembly assembly = Assembly.LoadFrom(spath); //spath is the path of .dll file
//其次,用加载的assembly来定义指定的类型,例如:
// Create new type
Type t = assembly.GetType("iGenDLL.GenDLL");
Type _DelegateType = assembly.GetType("iGenDLL.testOne");
object _Value = System.Activator.CreateInstance(t);
System.Reflection.EventInfo _Event = t.GetEvent("testOneEvent", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
Delegate _Deleage = Delegate.CreateDelegate(_DelegateType, _Value, "MyEvent"); //问题出现在这一行, Error binding totarget method
_Event.AddEventHandler(_Value, _Deleage); |
|