rutlean

I am getting a TargetParameterCountException occured "Parameter count mismatch" anytime an event is thrown. Given how early the event are being thrown, timers are throwing the events that cause the exception. The following is the message I get when the exception is thrown. All of this occurs after a splash screen is closed upon the mainform being loaded. As soon as the timer event is thrown, the mainform bombs out.

Any help will be greatly appricated.

Thanks,

Andy

System.Reflection.TargetParameterCountException: Parameter count mismatch.

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

at System.Delegate.DynamicInvokeImpl(Object[] args)

at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)

at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)

at System.Threading.ExecutionContext.runTryCode(Object userData)

at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)

at System.Windows.Forms.Control.InvokeMarshaledCallbacks()

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ContainerControl.WndProc(Message& m)

at System.Windows.Forms.UserControl.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.Run(Form mainForm)

at Windows_Host.Form1.Main() in C:\Documents and Settings\Administrator\Desktop\upgrade\TEDS Upgrade\2005 -New GUI V2 - without cel selection\TORQUE_CALIB\Software\GUI\WindowsHost\WindowsHost.cs:line 199



Re: Visual C# General TargetParameterCount Exception / Parameter count mismatch Issue

Steve Py

Post up the code from the timer trying to raise the event, and the event declaration.

If you're trying to raise one of the form's standard events you need to provide the parameters with the Invoke call. These typically consist of (object sender, EventArgs e) but the EventArgs subclass may vary depending on the event.





Re: Visual C# General TargetParameterCount Exception / Parameter count mismatch Issue

rutlean

private System.Timers.Timer timerDelay; //form member

Inside Constructor

timerDelay = new System.Timers.Timer(500);

timerDelay.Elapsed += new System.Timers.ElapsedEventHandler(timerDelay_Elapsed);

Delegate Defined for ThreadSafe Operation

delegate void timerDelay_ElapsedThreadSafe(object sender, System.Timers.ElapsedEventArgs e);

Event

private void timerDelay_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

{

timerDelay.Enabled = false;

if (InvokeRequired)

{

timerDelay_ElapsedThreadSafe timerDelay_ElapsedDelegate = new timerDelay_ElapsedThreadSafe(timerDelay_Elapsed);

this.BeginInvoke(timerDelay_ElapsedDelegate);

}

else

{

btnBegin.Enabled = true;

}

}

Thanks,

Andy





Re: Visual C# General TargetParameterCount Exception / Parameter count mismatch Issue

Steve Py

The error is caused by what I mentioned above, you're trying to invoke an event without passing the arguments.

Changing the BeginInvoke call would fix the exception:

this.BeginInvoke(timerDelay_ElapsedDelegate, sender, e)






Re: Visual C# General TargetParameterCount Exception / Parameter count mismatch Issue

rutlean

Thanks!! I was having a trouble finding any information on the error.