Can I avoid slow .net exceptions in DEBUG with the debugger attached?

One possible workaround you can do (I ran in to a similar issue where a image processing library would throw a OutOfMemoryException if used while the debugger was attached on a particularly large dataset) is put a breakpoint before calling in to the 3rd party library code and detaching the debugger, after the breakpoint re-attach the debugger with a Debugger.Launch().

#if DEBUG
bool debuggerAttached = Debugger.IsAttached;
if(debuggerAttached)
{
    Debugger.Break(); //Detach the debugger to make the next section faster.
}
#endif

TSqlParser parser = new TSql110Parser(false);
IList<ParseError> errors;
TSqlFragment fragment = parser.Parse(new StringReader(sqltext), out errors);

#if DEBUG
if(debuggerAttached && !Debugger.IsAttached)
{
    Debugger.Launch();
}
#endif

You can't stop the exceptions and first chance exceptions are slow under the debugger as the process is paused, operation is transferred over to the debugger to say whether it wants to know about it or not and then the client is restarted again (until the next one). That is how the Win32 Debug Api works I am afraid.

I do quite a lot of debugging of ScriptDom and the best I have come up with is parsing small scripts that are well formed and valid.

I try to limit the script to just the part that has an issue.

ed