M
Michael Moreno
Hello,
I am failing to understand why I get an invalid cast exception with
this very simple code.
I have derived the EventArgs class as follow:
public class StringArgs : System.EventArgs
{
public string Msg;
public StringArgs(string aMsg)
{
Msg = aMsg;
}
}
and I fire the event as shown below
private void EventLog(string Msg)
{
System.EventArgs e = new StringArgs(Msg);
object[] pList = { this, e };
BeginInvoke(new System.EventHandler(UpdateRTBLog), pList);
}
now when I receive the event in this method
private void UpdateRTBLog(object o, System.EventArgs e)
{
StringArgs se = (StringArgs) e;
RTBLog.Text = se.Msg;
}
I get during runtime an Invalid cast error:
"System.InvalidCastException: Specified cast is not valid." on
StringArgs se = (StringArgs) e;
Please would you be kind enough to tell me why this is happening and
how to fix this?
Many thanks for your help.
Michael
I am failing to understand why I get an invalid cast exception with
this very simple code.
I have derived the EventArgs class as follow:
public class StringArgs : System.EventArgs
{
public string Msg;
public StringArgs(string aMsg)
{
Msg = aMsg;
}
}
and I fire the event as shown below
private void EventLog(string Msg)
{
System.EventArgs e = new StringArgs(Msg);
object[] pList = { this, e };
BeginInvoke(new System.EventHandler(UpdateRTBLog), pList);
}
now when I receive the event in this method
private void UpdateRTBLog(object o, System.EventArgs e)
{
StringArgs se = (StringArgs) e;
RTBLog.Text = se.Msg;
}
I get during runtime an Invalid cast error:
"System.InvalidCastException: Specified cast is not valid." on
StringArgs se = (StringArgs) e;
Please would you be kind enough to tell me why this is happening and
how to fix this?
Many thanks for your help.
Michael