Omer van Kloeten's .NET Zen

Programming is life, the rest is mere details


Note: This blog has moved to

Omer van Kloeten's Facebook profile

Omer has been professionally developing applications over the past 8 years, both at the IDF’s IT corps and later at the Sela Technology Center, but has had the programming bug ever since he can remember himself.
As a senior developer at NuConomy, a leading web analytics and advertising startup, he leads a wide range of technologies for its flagship products.

Get Firefox

powered by Dapper 

.NET Resources

Articles :: CodeDom

Articles :: nGineer



Finding Out Why Control.Invoke Throws Undocumented Exceptions

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 Control.MarshaledInvoke:

       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 Invoke to BeginInvoke. to see if it might make a difference. This raised, instead of an ArgumentException, a TargetInvocationException, which in turn contained the original exception with its original stack trace. The problem was found and fixed.


No Comments