I've got a problem with an event rising. Here is my base class:
public abstract class MyClass<T>
{
public event EventHandler<MessageReceivedEventArgs<T>> MessageReceived;
protected void OnMessageReceived(MyClass<T> sender, MessageReceivedEventArgs<T> e)
{
EventHandler<MessageReceivedEventArgs<T>> handler = MessageReceived;
if (MessageReceived != null)
MessageReceived(sender, e);
}
}
And my implementation :
public class MyDerivedClass: MyClass<string>
{
void AFunction()
{
// Do some stuff
OnMessageReceived(this, new MessageReceivedEventArgs<string>("data"));
}
When OnMessageReceived
is called, the system throw a System.ArgumentNullException
("Value cannot be null. Parameter name: type"). I already read this thread, and this one too, which help me to construct this code. But I can't find the reason of these exception (sender
and e
are not null, checked with the debugger).
What am I doing wrong ?
EDIT : Here's my MessageReceivedEventArgs
implementation :
public class MessageReceivedEventArgs<T> : EventArgs
{
public T Data { get; private set; }
public MessageReceivedEventArgs(T data)
{
Data = data;
}
}