Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Let us consider I'm having an application named as AAA.
Now I'm Loading an assembly named as BBB .The assembly BBB is having the declaration of event and delegate.
The handler to the event in BBB is available in AAA.
While loading the assembly BBB, I need to add the handler for the event in AAA.
Whenever the event occur in BBB, I should execute the handler method in AAA.
How to accomplish this?
I coded like this in AAA:
Assembly tstComponent = Assembly.LoadFile(BBB);
Type Global = tstComponent.GetType(ClassInBBB, false, true);
if (Global != null)
{                
  EventInfo l_objevent = Global.GetEvent("OnGetdelInBBB");
  Type l_objEveType = l_objevent.EventHandlerType;
  Type Dis = Assembly.GetExecutingAssembly().GetType("AAA", false, true);
  MethodInfo l_method = Dis.GetMethod("HandlerinAAA");
  Delegate d = Delegate.CreateDelegate(l_objEveType, l_method);
  MethodInfo addHandler = l_objevent.GetAddMethod();
  Object[] addHandlerArgs = { d };
  addHandler.Invoke(Dis, addHandlerArgs);//getting System.Reflection.TargetException
}   

Please help me. Thanks in advance
Posted
Updated 25-Nov-10 19:52pm
v3
Comments
JF2015 26-Nov-10 1:20am    
Edited to improve spelling and code formatting.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900