{"id":3723,"date":"2012-12-11T11:47:00","date_gmt":"2012-12-11T11:47:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2012\/12\/11\/debugging-sharepoint-apps-with-intellitrace-in-visual-studio\/"},"modified":"2022-07-21T01:47:47","modified_gmt":"2022-07-21T09:47:47","slug":"debugging-sharepoint-apps-with-intellitrace-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/debugging-sharepoint-apps-with-intellitrace-in-visual-studio\/","title":{"rendered":"Debugging SharePoint Apps with IntelliTrace in Visual Studio"},"content":{"rendered":"<p>\u00a0<\/p>\n<p><span style=\"font-family: Calibri;font-size: small\">In this post we\u2019ll explore how to use <\/span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd264915(v=vs.110).aspx\"><span style=\"color: #0563c1;font-family: Calibri;font-size: small\">IntelliTrace<\/span><\/a><span style=\"font-family: Calibri;font-size: small\"> in <\/span><a href=\"http:\/\/www.microsoft.com\/visualstudio\/eng\/visual-studio-update\"><span style=\"color: #0563c1;font-family: Calibri;font-size: small\">Visual Studio 2012 Ultimate Update 2<\/span><\/a><span style=\"font-family: Calibri;font-size: small\"> to debug custom Web Parts in a <a href=\"http:\/\/office.microsoft.com\/en-us\/sharepoint\/sharepoint-2013-overview-collaboration-software-features-FX103789323.aspx\"><span style=\"color: #0563c1;font-family: Calibri;font-size: small\">SharePoint 2013<\/span><\/a>\u00a0<\/span><span style=\"font-size: small\"><span style=\"font-family: Calibri\">and\u00a0<a href=\"http:\/\/office.microsoft.com\/en-us\/microsoft-sharepoint-collaboration-software-FX103479517.aspx\"><span style=\"color: #0563c1;font-family: Calibri;font-size: small\">SharePoint 2010<\/span><\/a><a href=\"http:\/\/office.microsoft.com\/en-us\/sharepoint\/sharepoint-2013-overview-collaboration-software-features-FX103789323.aspx\"><span style=\"color: #0563c1;font-family: Calibri;font-size: small\">\u00a0<\/span><\/a> application. First we\u2019ll summarize SharePoint\u2019s use of correlation IDs and the IntelliTrace enhancements in VS2012 Update 2, and then we\u2019ll dive into a walkthrough.<\/span><\/span><\/p>\n<p>\u00a0<\/p>\n<h2><span style=\"color: #2e74b5\">SharePoint\u2019s Unified Logging System and Correlation IDs<\/span><\/h2>\n<p><span style=\"font-family: Calibri\">SharePoint has a built-in way of recording what happens during execution called the \u201c<\/span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff512738.aspx\"><span style=\"font-family: Calibri;color: #0563c1\">Unified Logging System<\/span><\/a><span style=\"font-family: Calibri\">\u201d or just \u201cULS\u201d for short. ULS is always running and the log files it generates tend to be the first things that a seasoned SharePoint developer examines when trying to diagnose a problem with a SharePoint application. <\/span><\/p>\n<p><span style=\"font-family: Calibri\">When debugging web applications, it is often helpful to reason about a web request in isolation because it can be considered as a neatly contained unit of \u201caction\u201d. SharePoint generates a unique <a href=\"http:\/\/sharepoint.microsoft.com\/blogs\/GetThePoint\/Lists\/Posts\/Post.aspx?ID=353\"><span style=\"color: #000000\">Correlation ID<\/span><\/a> for each incoming web request and tags each ULS log entry with the Correlation ID of its associated web request, which facilitates this method of debugging. Filtering by Correlation ID in a tool like <a href=\"http:\/\/ulsviewer.codeplex.com\/\"><span style=\"color: #000000\">ULS Viewer<\/span><\/a> allows you to focus on the isolated sequence of events in a single web request that exhibited the bug.IntelliTrace support for SharePoint in Update 2<\/span><\/p>\n<p><span style=\"font-family: Calibri;font-size: small\">For <\/span><a href=\"http:\/\/www.microsoft.com\/visualstudio\/eng\/visual-studio-update\"><span style=\"font-family: Calibri;color: #0563c1;font-size: small\">Update 2 of Visual Studio 2012,<\/span><\/a><span style=\"font-family: Calibri;font-size: small\"> we have extended the capabilities of IntelliTrace to support SharePoint diagnostics. If you are not familiar with IntelliTrace\u2019s existing support for ASP.NET websites, please <\/span><a href=\"https:\/\/channel9.msdn.com\/Shows\/Visual-Studio-Toolbox\/Collecting-IntelliTrace-Data-in-Production\"><span style=\"font-family: Calibri;color: #0563c1;font-size: small\">watch this tutorial<\/span><\/a><span style=\"font-size: small\"><span style=\"font-family: Calibri\">.<\/span><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">IntelliTrace now collects SharePoint ULS log entries as IntelliTrace events if the instrumented process is that of a SharePoint application. These ULS events, as well as all other IntelliTrace Events, have Correlation IDs included.<\/span><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">IntelliTrace associates events with specific web requests, but prior Update\u00a02 this association was not visible anywhere other than on a Web Request Details page, which only shows events that are in that web request. For Update 2, we made this filtering scheme also usable in the IntelliTrace window when debugging SharePoint applications. The Correlation ID conveniently serves as the web request\u2019s unique identifier in the filter string.<\/span><\/span><\/p>\n<p><span style=\"font-family: Calibri;font-size: small\">To enable these new features, all you have to do is use the <\/span><a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=30665\"><span style=\"font-family: Calibri;color: #0563c1;font-size: small\">latest standalone IntelliTrace collector<\/span><\/a><span style=\"font-size: small\"><span style=\"font-family: Calibri\"> on your SharePoint application and open the resulting log file in Visual Studio 2012 Ultimate with Update 2 installed.<\/span><\/span><\/p>\n<h2><span style=\"color: #2e74b5\">Walkthrough<\/span><\/h2>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">In the following walkthrough, we will debug a page in a SharePoint application that shows a cryptic error when we try to load it. We will collect an IntelliTrace log, open the log in Visual Studio, use the Correlation ID to find the faulty web request, and examine the log data to determine exactly where the bug is in the code. <\/span><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">We\u2019ve written a SharePoint application and one day our site just \u201cstopped working\u201d. That is, every time we try to access it, we get an error similar to the one shown below:<\/span><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\"><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/5466.pic1_.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/5466.pic1_.jpg\" alt=\"\" border=\"0\" \/><\/a><\/span><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Unfortunately, these error messages don\u2019t contain much information. Fortunately, they give us a Correlation ID with which we can dig deeper into the error. Let\u2019s use IntelliTrace to fix this bug. <\/span><\/span><\/p>\n<p><span style=\"font-family: Calibri;font-size: small\">First, <\/span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/vstudio\/hh398365.aspx\"><span style=\"font-family: Calibri;color: #954f72;font-size: small\">start collecting on the App Pool that contains the SharePoint application<\/span><\/a><span style=\"font-size: small\"><span style=\"font-family: Calibri\">. 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:<\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/5228.pic2_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Then, navigate to the SharePoint site to get the error page. Note the Correlation ID:<\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/4784.pic3_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">After the page finishes loading, stop collecting on the App Pool:<\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/7462.pic4_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Now we navigate to the \u201cIntelliTraceLogs\u201d folder and open the IntelliTrace log:<\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/4786.pic5_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Visual Studio will display the IntelliTrace summary page upon opening the log: <\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/7215.pic6_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Since we already have the Correlation ID given by that error page, we can simply copy and paste it into the textbox and click \u201cView Details\u201d: <\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/0312.pic7_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">This brings up the Web Request Details page, which has information about the web request associated with the Correlation ID we entered. The list here contains only events that are part of that web request:<\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/4101.pic8_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">This list can be filtered in various ways. For example, we could use the dropdown to specify that we want to see only SharePoint ULS events, which is usually the most relevant category when debugging a SharePoint application. The error page said that the error was \u201cunexpected\u201d, so we should search for \u201cunexpected\u201d events to see the actual ULS event logged by SharePoint for that error:<\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/1581.pic9_.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">The unexpected event says that it was caused by a System.Net.WebException. This clue tells us that we should search for exceptions that have the type \u201cWebException\u201d:<\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/1072.pic10.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Looks like there was only one of these exceptions thrown during our reproduction of the bug. This must be the cause! We can double click the event or click \u201cStart Debugging\u201d to go directly to code: <\/span><\/span><\/p>\n<p><span style=\"font-family: Calibri;font-size: small\">\u00a0<a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/5344.pic11.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/5344.pic11.jpg\" alt=\"\" border=\"0\" \/><\/a><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Note that the IntelliTrace window has been filtered to show only events in the web request threw the unhandled exception. The string \u201cWebRequest:9de42c72-cbd1-4882-bee4-e83e3ddc3c50\u201d indicates that the list has been scoped to the web request that was assigned that specific Correlation ID (the same one in our error page) by SharePoint.<\/span><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">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: <\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/3757.pic12.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">After re-deploying, our page now works just fine: <\/span><\/span><\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/12\/8182.pic13.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<h2><span style=\"color: #2e74b5\">Conclusion<\/span><\/h2>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">With IntelliTrace in Visual Studio Ultimate 2012 Update 2, SharePoint developers who are familiar with Correlation IDs now have a way of directly using them to debug their code. This is just one of the ways we\u2019ve made Visual Studio more convenient for SharePoint development.<\/span><\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"font-family: Calibri\">We greatly appreciate your questions and feedback, so please leave your comments below!<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 In this post we\u2019ll explore how to use IntelliTrace in Visual Studio 2012 Ultimate Update 2 to debug custom Web Parts in a SharePoint 2013\u00a0and\u00a0SharePoint 2010\u00a0 application. First we\u2019ll summarize SharePoint\u2019s use of correlation IDs and the IntelliTrace enhancements in VS2012 Update 2, and then we\u2019ll dive into a walkthrough. \u00a0 SharePoint\u2019s Unified Logging [&hellip;]<\/p>\n","protected":false},"author":90,"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-3723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>\u00a0 In this post we\u2019ll explore how to use IntelliTrace in Visual Studio 2012 Ultimate Update 2 to debug custom Web Parts in a SharePoint 2013\u00a0and\u00a0SharePoint 2010\u00a0 application. First we\u2019ll summarize SharePoint\u2019s use of correlation IDs and the IntelliTrace enhancements in VS2012 Update 2, and then we\u2019ll dive into a walkthrough. \u00a0 SharePoint\u2019s Unified Logging [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3723","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\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=3723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3723\/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=3723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=3723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=3723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}