Debugging Tips
Debugging Tobi can be challenging. The source of deep exceptions is sometimes hard to find (i.e. the execution stack trace doesn't make much sense), and exceptions tend to be swallowed by:
- Visual Studio, as per the {Debug -> Exceptions} menu,
- the Dependency Injection container (Unity), which has to deal with several layers of assemblies (each Module is a separate DLL).
One rule of thumb is to always dig inside the "Inner Exception" recursive field of the exception popup window. A recurrent example is System.Reflection.TargetInvocationException, which hides valuable information in the InnerException field. Dig-in ! :)
In addition, the best strategy I have found so far is to enable all exceptions in Debug -> Exceptions: this way, Visual Studio becomes ultra verbose and the debugger captures every exception, even "first-chance" ones. To avoid annoying exception spam though, we need to selectively untick the following items:
- in "Managed Debugging Assistants"
- LoaderLock (generated by DirectSound)
- AsynchronousThreadAbort (raised when we interrupt a thread programmatically by force, such as in the Audio Player/Recorder?)
- in "Common Language Runtime Exceptions"
- System.Threading.SynchronizationLockException (thrown by the DI-C)
- System.Deployment.Application.InvalidDeploymentException (raised when loading images from URL in the DTBook document)
- System.NotSupportedException (ditto)
- System.IO.DirectoryNotFoundException (ditto)
- System.Net.WebException (ditto, this one needs to be added manually, there is no built-in tick-box)
- System.IO.IOException (generated by the MSXML parser when trying to load the ePub DTDs)
This debugging method works only for first-chance exceptions that do not make the application crash.
For example, some IOExceptions are likely to be fatal if not handled properly, so the application will crash anyway (i.e. pressing F5 won't work), but unfortunately our current ePub import generates tons of IOExceptions so we need to let the application run automatically (pressing F5 hundreds of times is not fun). We are in the process of fixing the DTD processing, when it's done, the IOExceptions will disappear.
