{"id":17915,"date":"2018-05-24T10:00:16","date_gmt":"2018-05-24T17:00:16","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/?p=17915"},"modified":"2019-02-14T15:23:45","modified_gmt":"2019-02-14T23:23:45","slug":"snapshots-on-exceptions-while-debugging-with-intellitrace","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/snapshots-on-exceptions-while-debugging-with-intellitrace\/","title":{"rendered":"Snapshots on Exceptions while debugging with IntelliTrace"},"content":{"rendered":"<p>Have you ever encountered an exception in your application while debugging, and wanted to know exactly what the state of the app was at that point in time? Or, you\u2019re debugging async code and you want to know the context in which an exception was thrown? Now, with a new feature in <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/debugger\/how-to-use-intellitrace-step-back\">IntelliTrace step-back<\/a>, you can!<\/p>\n<p>Starting in <a href=\"https:\/\/www.visualstudio.com\/thank-you-downloading-visual-studio\/?sku=Enterprise&amp;rel=15\">Visual Studio Enterprise 2017 version 15.7<\/a>, IntelliTrace will now automatically take snapshots on exception events, in addition to breakpoints and debugger steps. This enables you to go back to a previous exception event and see the state of the application at the time the exception was thrown.<\/p>\n<p>Exception events are the most widely used IntelliTrace event, and we\u2019re excited to be able to address a top customer ask.<\/p>\n<h2>Enabling snapshots on exception events<\/h2>\n<p>To enable this feature, go to <b>Tools<\/b> -&gt; <b>Options<\/b> -&gt; <b>IntelliTrace<\/b> settings, and select the option \u201cIntelliTrace events and snapshots.\u201d By default, IntelliTrace will collect a maximum of five snapshots on exception events between break states \u2013 e.g. between debugger steps or breakpoints. This number can be configured in IntelliTrace advanced settings.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/EnableSnapshots_settings.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/EnableSnapshots_settings.png\" alt=\"Enable this feature in Tools - Options - IntelliTrace by selecting &quot;IntelliTrace events and snapshots&quot;\" width=\"1403\" height=\"946\" class=\"aligncenter size-full wp-image-18830\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/EnableSnapshots_settings.png 1403w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/EnableSnapshots_settings-300x202.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/EnableSnapshots_settings-768x518.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/EnableSnapshots_settings-1024x690.png 1024w\" sizes=\"(max-width: 1403px) 100vw, 1403px\" \/><\/a><\/p>\n<h2>Debugging with snapshots on exceptions<\/h2>\n<p>Let\u2019s walk through an example of how we can use this feature while debugging an application.<\/p>\n<p>In my shuttle application, I see that when I F5 to debug it, I get an error. The driver details are not appearing as expected.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Error.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Error.png\" alt=\"The driver details and headshot picture does not show as expected\" width=\"891\" height=\"545\" class=\"aligncenter size-full wp-image-18831\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Error.png 891w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Error-300x184.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Error-768x470.png 768w\" sizes=\"(max-width: 891px) 100vw, 891px\" \/><\/a><\/p>\n<p>In Visual Studio, IntelliTrace has recorded an exception event in the Diagnostic Tools window. The camera icon indicates that there is a snapshot available.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/DiagToolsWindow_SnapshotOnException.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/DiagToolsWindow_SnapshotOnException.png\" alt=\"Camera icon on the Exception indicates there is a snapshot available\" width=\"768\" height=\"742\" class=\"aligncenter size-full wp-image-18832\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/DiagToolsWindow_SnapshotOnException.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/DiagToolsWindow_SnapshotOnException-300x290.png 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p>To view the snapshot, double-click on the event, or select the event and click the \u2018Activate Historical Debugging\u2019 link.<\/p>\n<p>Visual Studio is now in Historical Debugging mode at the line of code where the exception was thrown.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/SnapshotsOnExceptions_VS_15-7.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/SnapshotsOnExceptions_VS_15-7.png\" alt=\"Visual Studio is in historical debugging mode\" width=\"2560\" height=\"1376\" class=\"aligncenter size-full wp-image-18833\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/SnapshotsOnExceptions_VS_15-7.png 2560w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/SnapshotsOnExceptions_VS_15-7-300x161.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/SnapshotsOnExceptions_VS_15-7-768x413.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/SnapshotsOnExceptions_VS_15-7-1024x550.png 1024w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/a><\/p>\n<p>From here, you\u2019ll be able to see the historical values of your Call Stack, Locals, and Watches, just as you would in regular, live debugging. You can also evaluate expressions in the Watch Window and hover over variables to see data tips. All these values are populated using the data from the snapshot.<\/p>\n<p>Using this information, I can see from the Locals window that the exact value of driver.name was null. In this query, we should have done the comparison on driver.id.<\/p>\n<p>By changing the query to in line 161 to:<\/p>\n<p>selectedDriver = drivers.Where(d =&gt; driver.id.Equals(d.DriverId)).FirstOrDefault();<\/p>\n<p>the issue is fixed. Now, the driver shows up!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Fixed.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Fixed.png\" alt=\"The issue is fixed and now the driver headshot picture shows\" width=\"867\" height=\"533\" class=\"aligncenter size-full wp-image-18834\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Fixed.png 867w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Fixed-300x184.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/05\/Shuttle_App_Fixed-768x472.png 768w\" sizes=\"(max-width: 867px) 100vw, 867px\" \/><\/a><\/p>\n<p>To minimize redundant snapshots and improve performance, IntelliTrace will only take snapshots on exception \u2018thrown\u2019 events under certain conditions. The first time an exception is thrown, IntelliTrace will take a snapshot and mark it accordingly. If this exception is caught and then rethrown or wrapped as an inner exception to another thrown exception \u2013 no snapshot will be taken on these events, nor any exception events associated with the original exception. Additionally, IntelliTrace will not take snapshots on exceptions with the same type and call stack as an existing exception event that already has a snapshot.<\/p>\n<h2>Try it out<\/h2>\n<p>The IntelliTrace snapshots on exceptions feature is available in <a href=\"https:\/\/www.visualstudio.com\/thank-you-downloading-visual-studio\/?sku=Enterprise&amp;rel=15\">Visual Studio Enterprise 2017 version 15.7<\/a> and requires Windows 10 Anniversary Update or above. The feature is currently supported for ASP.NET, ASP.NET Core, .NET Core, WinForms, WPF, managed console apps, and managed class libraries.<\/p>\n<p>We\u2019d love to hear your feedback. To report issues, use the <a href=\"https:\/\/aka.ms\/vs-rap\">Report a Problem<\/a> tool in Visual Studio. You\u2019ll be able to track your issues in the <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Visual Studio Developer Community<\/a> where you can ask questions and find answers. You can also make a product suggestion through <a href=\"https:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio-ide\/category\/31799-debugging-and-diagnostics\">UserVoice<\/a>, or email the team directly at stepback@microsoft.com.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever encountered an exception in your application while debugging, and wanted to know exactly what the state of the app was at that point in time? With a new feature in IntelliTrace, you can! Learn how to use IntelliTrace&#8217;s new snapshots on exceptions feature, which enables you to go back to a previous exception event and see the state of the application at the time the exception was thrown.<\/p>\n","protected":false},"author":592,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1196,155],"tags":[237,85,9,287,182,156],"class_list":["post-17915","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-desktop","category-visual-studio","tag-net","tag-asp-net","tag-debug","tag-tips-and-tricks","tag-unity","tag-visual-studio-2017"],"acf":[],"blog_post_summary":"<p>Have you ever encountered an exception in your application while debugging, and wanted to know exactly what the state of the app was at that point in time? With a new feature in IntelliTrace, you can! Learn how to use IntelliTrace&#8217;s new snapshots on exceptions feature, which enables you to go back to a previous exception event and see the state of the application at the time the exception was thrown.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/17915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/592"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=17915"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/17915\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=17915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=17915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=17915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}