Debugging Addins

It can be challenging to debug Outlook add-ins that are created with VSTO if you haven't set your debugger to stop on all exceptions. This is because Outlook often swallows the exceptions that are thrown (meaning that they are not bubbled up from the Outlook application to your Visual Studio debugging session); by default, the code will not break into the debugger. Either you can set the debugger to break on all exceptions, or you can use Try Catch blocks to trap and handle the errors. For more about debugging VSTO solutions, see Chapter 2, and for more on using Try Catch statements, see Chapter 3.

Another way to troubleshoot problems with add-ins is to write errors to a log file. By default, Outlook does not automatically log errors. You can change this by adding an environment variable called VSTO_LOGALERTS and setting its value to 1. The log is created in the same folder that contains the application manifest for the Outlook add-in. If you prefer to display the error in a message box, you can create an environment variable called VSTO_SUPRESSSDISPLAYALERTS and set its value to zero.

To modify environment variables, click Environment Variables in the System Properties dialog box, and then click New in the Environment Variables dialog box, as shown in Figure 10.14.

Keep in mind that you should always close the debug sessions by closing Outlook so that any cleanup code is called correctly. When you stop debugging from VSTO, it shuts down Outlook, potentially damaging the .OST file (Outlook's offline store). Normally, Outlook can repair this damage, but it could take a few minutes at startup. Thus, it is always

Figure 10.14. Creating environment variables to log VSTO errors

advisable to stop debugging by closing the host application (Outlook). You might also want to run Clean on the add-in if you want to unload it from outside Outlook. To do this, right-click the project and then select Clean in the context menu. Also, keep in mind that Outlook disables any add-ins that fail during startup.

0 0

Post a comment