It it possible to register an event using the System.Reflection 
Author Message
 It it possible to register an event using the System.Reflection

I'm trying to wire-up and event that will be raised from a late-bound
object.  I am using the System.Reflection so that I can see the events in
that MyObj...e.g...
~~~~~~~~~~
Dim MyObj as Object
Dim MyEvents() as Reflection.EventInfo
Dim Location as String
Dim MyAssembly as Reflection.Assembly

MyAssembly  = MyAssembly.LoadFrom("C:\pathtoprog\myprog.dll")
MyObj= MyAssembly.CreateInstance("MyProj.MyClass")
MyEvents = MyObj.GetType.GetEvents
~~~~~~~~~~
Now that I can see the events in MyObj...how do I wire them up so that they
are caught when they are raised from MyObj?

I'm stumped, Any suggestions would be great...

Thanx,
Matt



Sun, 18 Jan 2004 20:15:51 GMT  
 It it possible to register an event using the System.Reflection
Matt,

Quote:
>Now that I can see the events in MyObj...how do I wire them up so that they
>are caught when they are raised from MyObj?

MyEvents(idx).AddEventHandler(MyObj, AddressOf YourHandlerMethod)

Mattias

====================================

http://www.msjogren.net/dotnet/

CodeHound - The Software Developer's Search Engine
http://www.codehound.com



Wed, 21 Jan 2004 18:36:06 GMT  
 It it possible to register an event using the System.Reflection
Mattias,

    Thanks for the response...using the code you suggested I get the
following error...

~~~~~~~~~~~~~~
System.ArgumentException: Object type cannot be converted to target type.
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Reflection.EventInfo.AddEventHandler(Object target, Delegate
handler)
   at CKMainExeTest.frmCKMain.btnLoad_Click(Object sender, EventArgs e) in
E:\DevProjects\vb.net\CKMainExeTest\Form1.vb:line 88
~~~~~~~~~~~~~~~

Do you have any idea why this type of exception would occur?

Thanks,
Matt


Quote:
> Matt,

> >Now that I can see the events in MyObj...how do I wire them up so that
they
> >are caught when they are raised from MyObj?

> MyEvents(idx).AddEventHandler(MyObj, AddressOf YourHandlerMethod)

> Mattias

> ====================================

> http://www.msjogren.net/dotnet/

> CodeHound - The Software Developer's Search Engine
> http://www.codehound.com



Sun, 25 Jan 2004 09:48:18 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Possible to use Reflection on Registry Class?

2. Release a reference from System.Reflection

3. How far can System.Reflection take you?

4. System.Reflection.Emit

5. documentation- attributes and the system.reflection object

6. VB2008: Getting the System.Reflection.PropertyInfo from within a class property

7. Setting a value in a structure using Reflection

8. Dynamic loading forms using reflection

9. Using Reflection to load Composite Control

10. Missing assembly when using reflection to call component method

11. Using reflection to create class instance

12. Using a WRQ Reflection Session in a VB 6 Program

 

 
Powered by phpBB® Forum Software