In .Net 4 this code run with no error
class A
{
public event EventHandler<CustomEventArgs> MyEvent;
}
where CustomEventArgs derived from EventArgs
void Test()
{
A a = new A();
a.MyEvent += MyFunc;
}
void MyFunc(object sender, EventArgs args) // EventArgs expect of CustomEventArgs
{
}
Now, when I try to do the same by reflection I get can't cast delegate exception
EvemtInfo myEvent = ... // get event somehow
myEvent.AddEventHandler(a, new EventHandler<EventArgs>(ConnectResponseReceived));
How can I do the same it in reflection?