{"id":3483,"date":"2013-02-05T16:03:00","date_gmt":"2013-02-05T16:03:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2013\/02\/05\/debugging-unhandled-exceptions-in-a-sharepoint-app-with-visual-studio-using-intellitrace\/"},"modified":"2022-07-21T00:43:35","modified_gmt":"2022-07-21T08:43:35","slug":"debugging-unhandled-exceptions-in-a-sharepoint-app-with-visual-studio-using-intellitrace","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/debugging-unhandled-exceptions-in-a-sharepoint-app-with-visual-studio-using-intellitrace\/","title":{"rendered":"Debugging Unhandled Exceptions in a SharePoint App with Visual Studio using IntelliTrace"},"content":{"rendered":"<p>Following on from our last blog post on <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/12\/11\/debugging-sharepoint-apps-with-intellitrace-in-visual-studio.aspx\">IntelliTrace enhancements for SharePoint<\/a>, in this blog post we\u2019ll talk about how the new analysis section for SharePoint can help you find the source of issues faster.<\/p>\n<h2>The New Analysis Section<\/h2>\n<p>IntelliTrace is very good at providing a lot of data to you for debugging, but there is such a thing as \u201ctoo much\u201d data. When a lot of information is available, it can be hard to figure out what to look for and how to find it. To help you pinpoint bugs more quickly, we\u2019ve added an Analysis section to the IntelliTrace Summary Page, which is the first thing that you will see when you open an IntelliTrace log. This new section strives to be \u201csmart\u201d about the data it presents; that is, it will point you towards places in your code that are likely to contain bugs. The Analysis section is populated by analyzing the log (hence the name) to look for the specific patterns and events that indicate problems.<\/p>\n<p>In Update 1, the analysis section is focused squarely on highlighting unhandled exceptions in SharePoint applications.<\/p>\n<p>An exception is considered \u201cunhandled\u201d in a SharePoint (and ASP.NET) application if it has propagated to the global exception handler. Such an exception in a SharePoint application usually results in a rather cryptic error page:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/8540.PageError.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u2026which doesn\u2019t contain much information at all. Such errors\u00a0are severe enough that they are almost never considered \u201cnormal\u201d behavior. Hence, Visual Studio will aggregate occurrences of such unhandled exceptions into the Analysis section when it encounters them in an IntelliTrace log, so that you can start debugging them directly from the summary page.<\/p>\n<h2>Walkthrough<\/h2>\n<p>In the following walkthrough, we will debug a SharePoint page that contains such an unhandled exception, and use the new Analysis section to quickly get to the relevant piece of code. You may recall the example from our last <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/12\/11\/debugging-sharepoint-apps-with-intellitrace-in-visual-studio.aspx\">IntelliTrace<br \/>\nwith SharePoint<\/a> blog post.<\/p>\n<p>First, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/vstudio\/hh398365.aspx\">start collecting on the App Pool that contains the SharePoint application<\/a>. Specifically look at steps 1-4 in the \u2018How do I get started\u2019 section. In this example the App Pool is called \u201cSharePoint \u2013 80\u201d, we used the default collection plan, and we told IntelliTrace to put collected logs into a folder called \u201cIntelliTraceLogs\u201d on the Desktop:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/6433.SPCollection.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>Then, navigate to the SharePoint site to get the error page. Note the Correlation ID:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/0181.PageError2.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>After the page finishes loading, stop collecting on the App Pool:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/7587.PSStopCollection.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>Now we navigate to the \u201cIntelliTraceLogs\u201d folder and open the IntelliTrace log:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/6012.OpenLog.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>Visual Studio will display the IntelliTrace summary page upon opening the log:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/1680.LogSummary.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>Note that the analysis section here has a list with an item that tells you that IntelliTrace has \u201cfound 1 unhandled exception(s) with type: System.Net.WebException\u201d. The item in this list represents all the unhandled exceptions with this type and the same call stack, as the page explains. Also note that the Correlation ID in that drop-down box is identical to the one found on the error page.<\/p>\n<p>At this point, we can expand the Call Stack to determine the method in which this exception was thrown, and the sequence of method calls that led up to it:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/6874.AnalysisSection.jpg\" alt=\"\" border=\"0\" \/>\nTo go to code, just click \u201cDebug Exception\u201d. This will bring you to the place where the exception was thrown:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/2046.LogReplay.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>Note: If you see the message \u201cSymbols not found\u201d, Visual Studio can\u2019t resolve the source locations. Make sure the application\u2019s symbol (.pdb) files are in the Visual Studio symbol path. See <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/tfs\/ms241613.aspx\">Find symbol (.pdb) files and source files<\/a>.<\/p>\n<p>Here is a zoomed in screenshot of the relevant portion from the IntelliTrace window:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/1122.LogEvents.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>Note that the IntelliTrace window has been filtered to show only events in the web request that threw the unhandled exception. The string \u201cWebRequest:9de42c72-cbd1-4882-bee4-e83e3ddc3c50\u201d indicates that the list has been filtered to the web request that was assigned that specific Correlation ID (the same one in our error page and in the drop-down list) by SharePoint.<\/p>\n<p>It seems that the service we were trying to use was down. Maybe it\u2019ll come back later. The fix is easy: just catch the exception and display a notification message informing users about the situation:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/6138.CodeIssue.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>After re-deploying, our page now works just fine:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/2577.WorkingPage.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<h2>Conclusion<\/h2>\n<p>The Analysis section makes it possible to skip many tedious steps when debugging bugs caused by unhandled exceptions. Compare the single click needed here to go to code with the manual analysis done in the <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/12\/11\/debugging-sharepoint-apps-with-intellitrace-in-visual-studio.aspx\">previous post<\/a>.<\/p>\n<p>If you have ideas or suggestions, leave them in the comments below. We appreciate your feedback!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following on from our last blog post on IntelliTrace enhancements for SharePoint, in this blog post we\u2019ll talk about how the new analysis section for SharePoint can help you find the source of issues faster. The New Analysis Section IntelliTrace is very good at providing a lot of data to you for debugging, but there [&hellip;]<\/p>\n","protected":false},"author":89,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[226,1,225],"tags":[],"class_list":["post-3483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>Following on from our last blog post on IntelliTrace enhancements for SharePoint, in this blog post we\u2019ll talk about how the new analysis section for SharePoint can help you find the source of issues faster. The New Analysis Section IntelliTrace is very good at providing a lot of data to you for debugging, but there [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/89"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=3483"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=3483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=3483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=3483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}