C#
Every time I run my porgram I get this exception:

But when I run in debug mode, there i
TargetInvocationException masks the real exception by telling you that it crashed during "a method invocation", usually through something.Invoke.
What you have to do is look at the InnerException property of the exception object (the TargetInvocationException object), this will give you the actual exception that was thrown, with a more useful stack trace.