Hello
I am receving an ArgumentException from the following code, I am struggling to understand it the last entry in the stack trace is
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr,
Binder binder, Object[] parameters, CultureInfo culture,
Boolean verifyAccess, StackCrawlMark& stackMark)
When I step through the DeviceResponse is populated as I expect and the target is located and as expected but the targetForm.Invoke throws everytime
Any help would be much appreciated.
The event is defined as:
public static event EventHandler<MsgEventArgs<DeviceResponse>> DeviceResponseReceived;
The event is being raised from this code:
//Raise the event
if (DeviceResponseReceived != null)
{
if (DeviceResponseReceived.Target is System.Windows.Forms.Form)
{
System.Windows.Forms.Form targetForm = DeviceResponseReceived.Target as System.Windows.Forms.Form;
targetForm.Invoke(DeviceResponseReceived, new MsgEventArgs<DeviceResponse>(deviceResponse));
}
}
The MsgEventArgs is a generic event arguments class deriving from EventArgs:
public class MsgEventArgs<T> : EventArgs
{
public MsgEventArgs(T value)
{
m_value = value;
}
private T m_value;
public T Value
{
get { return m_value; }
}
}
In my form I have registered for the event in the forms constructor:
DeviceResponse.DeviceResponseReceived += new EventHandler<MIASmartClient.Messaging.Transport.MsgEventArgs<DeviceResponse>>(DeviceResponse_DeviceResponseReceived);
With the implementation as:
void DeviceResponse_DeviceResponseReceived(object sender, MIASmartClient.Messaging.Transport.MsgEventArgs<DeviceResponse> e)
{
_presenter.DeviceResponseReceived(e.Value);
}
Thanks for taking the time to have a look