A colleague was baffled by having
Control.Invoke (when called from a different thread) throw an
ArgumentException at him and asked if I knew what was happening. Opening the stack trace, I found that the exception originated from
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object args) [ user code...]
This meant that the exception was either raised from an undocumented source or that the exception had been rethrown with the original stack trace deleted.
To debug this further, I changed
BeginInvoke. to see if it might make a difference. This raised, instead of an
TargetInvocationException, which in turn contained the original exception with its original stack trace. The problem was found and fixed.