{"id":2213,"date":"2013-11-25T17:37:00","date_gmt":"2013-11-25T17:37:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2013\/11\/25\/just-my-code-for-asp-net-in-visual-studio-2013\/"},"modified":"2022-07-18T08:51:17","modified_gmt":"2022-07-18T16:51:17","slug":"just-my-code-for-asp-net-in-visual-studio-2013","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/just-my-code-for-asp-net-in-visual-studio-2013\/","title":{"rendered":"Just My Code for ASP.NET in Visual Studio 2013"},"content":{"rendered":"<p><em>Posting this on behalf of <a href=\"http:\/\/social.msdn.microsoft.com\/profile\/Patrick%20Nelson%20-%20MSFT\">Patrick Nelson<\/a> who is a developer on the Visual Studio Debugger team, and also thanks to Rob Paveza for his help with both of our post regarding JavaScript Just My Code<\/em><\/p>\n<p>Do you develop web apps? Do you hate when the debugger keeps stopping in code you don\u2019t care about? Are you tired of accidently stepping into JQuery? In Visual Studio 2013 with Internet Explorer 11, we\u2019ve added <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dn457346.aspx#BKMK_JavaScript_Just_My_Code\">Just My Code for JavaScript<\/a> to help with these very problems.<\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2013\/09\/19\/just-my-code-for-javascript-windows-store-apps-in-visual-studio-2013.aspx\">In our previous blog post we announced Just My Code for JavaScript and discussed it in the context of Windows Store apps<\/a>. In this complementary blog post I will cover the addition of Just My Code for JavaScript when debugging ASP.NET applications in Visual Studio 2013\u00a0using Internet Explorer 11 (*NOTE: *\u00a0Just My Code requires both Visual Studio 2013 and Internet Explorer 11, the JavaScript Just My Code feature will not work with prior versions of Internet Explorer).<\/p>\n<p>I\u2019m going to run through some examples in this post. If you want to try them yourself, create a new ASP.NET Web Application. I created an MVC app via New Project -> Visual C# -> Web -> ASP.NET Web Application. After hitting \u201cOK\u201d, select MVC and \u201cOK\u201d again.<\/p>\n<p>Create a new script file name Test.js in the \u201cScripts\u201d folder with this content:<\/p>\n<pre>function test1() {\n    var result = 1;\n    $([5, 10, 20, 40]).each(function (index, item) {\n        result *= item;\n    });\n\n    alert(\"Result = \" + result);\n}\n\nfunction test2() {\n    try\n    {\n        var a = undefinedFunction();\n    }\n    catch(e)\n    {\n        Debug.writeln(\"Caught exception \" + e);\n    }\n}<\/pre>\n<p>In about.cshtml, add the following html code:<\/p>\n<pre>&lt;script src=\"http:\/\/blogs.msdn.com\/Scripts\/Test.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;li&gt;\n      &lt;a onclick=\"test1()\"&gt;Run test1&lt;\/a&gt;\n&lt;\/li&gt;\n&lt;li&gt;\n      &lt;a onclick=\"test2()\"&gt;Run test2&lt;\/a&gt;\n&lt;\/li&gt;<\/pre>\n<h3>Stepping into JQuery<\/h3>\n<p>Set a breakpoint in Test.js line 3 ($([5, 10, 20, 40]).each(function (index, item) {), start debugging, then go to the \u201cAbout\u201d page. If you click on Run test1, you\u2019ll hit the breakpoint in Test.js. If you try stepping into this statement with an older version of Visual Studio (or Visual Studio 2013 with Just My Code turned off), you\u2019ll see something like this:<\/p>\n<p><img decoding=\"async\" style=\"border: 0px\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/11\/6574.image_thumb_52E80068.png\" alt=\"image\" width=\"664\" height=\"488\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>This is definitely not the best debugging experience because most developers don\u2019t care to go stepping through JQuery code. This behavior may also be very confusing to a novice developer. With Visual Studio 2013 and Just My Code, the same step operation will take you directly to the first call to your anonymous function:<\/p>\n<p><img decoding=\"async\" style=\"border: 0px\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/11\/1200.image_thumb_676D4FE6.png\" alt=\"image\" width=\"676\" height=\"497\" border=\"0\" \/><\/p>\n<p>If you look at the Call Stack window, you\u2019ll notice some grayed out frames named \u201c[External Code]\u201d. If you are interested in seeing what the external code is doing, you can take a look at it by right clicking in the Call Stack window, and selecting \u201cShow External Code\u201d:<\/p>\n<p><img decoding=\"async\" style=\"border: 0px\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/11\/1715.image_thumb_2017F9F4.png\" alt=\"image\" width=\"432\" height=\"391\" border=\"0\" \/><\/p>\n<h3>Exceptions<\/h3>\n<p>If you have ever tried to enable stopping on first chance exceptions, you\u2019ve probably seen screens like this many times:<\/p>\n<p><img decoding=\"async\" style=\"border: 0px\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/11\/5444.image_thumb_5041D568.png\" alt=\"image\" width=\"666\" height=\"489\" border=\"0\" \/><\/p>\n<p>You can try this yourself by going to Debug -> Exceptions, and enabling the debugger to stop when exceptions are thrown (also called first chance exceptions) for all JavaScript exceptions:<\/p>\n<p><img decoding=\"async\" style=\"border: 0px\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/11\/8512.image_thumb_16BEC571.png\" alt=\"image\" width=\"579\" height=\"289\" border=\"0\" \/><\/p>\n<p>If you turn off Just My Code, enable first chance exceptions, and refresh the <em>About<\/em> page, you\u2019ll be greeted with the screen above. In fact if you leave this setting on, you\u2019ll be inundated with first chance exceptions in code you aren\u2019t interested in while trying to debug your code. I tried this and had to push \u201cContinue\u201d (F5) 28 times before the <em>About<\/em> page loaded. Once you turn on Just My Code, <strong>all<\/strong> of these exceptions are ignored automatically since they are not in your code. If you want to stop at a first chance exception, click on the \u201cRun test2\u201d link. With stop on first chance exceptions enabled, the debugger will stop on the first chance exception in Test.js:<\/p>\n<p><img decoding=\"async\" style=\"border: 0px\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/11\/7610.image_thumb_645AF1F1.png\" alt=\"image\" width=\"673\" height=\"498\" border=\"0\" \/><\/p>\n<h3>Summary<\/h3>\n<p>In this post I briefly walked you through Just My Code for JavaScript when debugging ASP.NET applications in Visual Studio 2013. We discussed a few of the benefits and showed an overview of the behavior for stepping and exceptions. If you would like a more detailed description of the exact behavior in various situations and how to customize what is considered Just My Code please refer to <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2013\/09\/19\/just-my-code-for-javascript-windows-store-apps-in-visual-studio-2013.aspx\">the aforementioned previous blog post<\/a> or <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dn457346.aspx#BKMK_JavaScript_Just_My_Code\">the MSDN documentation<\/a>.<\/p>\n<p>If you have any questions or comments please let us know by either commenting below or posting in our <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/vsdebug\/threads\">MSDN forum<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Posting this on behalf of Patrick Nelson who is a developer on the Visual Studio Debugger team, and also thanks to Rob Paveza for his help with both of our post regarding JavaScript Just My Code Do you develop web apps? Do you hate when the debugger keeps stopping in code you don\u2019t care about? [&hellip;]<\/p>\n","protected":false},"author":68,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,225],"tags":[],"class_list":["post-2213","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>Posting this on behalf of Patrick Nelson who is a developer on the Visual Studio Debugger team, and also thanks to Rob Paveza for his help with both of our post regarding JavaScript Just My Code Do you develop web apps? Do you hate when the debugger keeps stopping in code you don\u2019t care about? [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/2213","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\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=2213"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/2213\/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=2213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=2213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=2213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}