35

I just installed VS 2010 Beta 2 and wanted to play with an ASP.NET MVC 2 project. I simply added some script (alert('hello');) into the Home controller's index.aspx view, and I can see it executing. When I try to set a breakpoint, however, it never gets hit. I also tried to use the "debugger" keyword, and when I do, I get a disappointing "there is no source code available for the current location" message. I also get this message when I try to independently attach to an IE process where my app is running.

What do I need to do to get a friendly script debugging experience? (I have successfully used Firebug to debug this, but for some reason I prefer the VS debugger.)

Here are some details of my configuration:

  • I am launching my stuff in VS 2010 Beta 2.
  • IE8 version 8.0.7600.16385 is my default browser.
  • The "Disable script debugging (Internet Explorer)" advanced option is unchecked.
  • The "Disable script debugging (Other)" option is unchecked.
  • In my ASP.NET MVC 2 project's "web" properties tab, the ASP.NET debugger is checked. All others are unchecked.
  • Visual Studio 2008 script debugging seems to work just fine.
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Chris Farmer
  • 24,974
  • 34
  • 121
  • 164

8 Answers8

30

The debugger cannot debug both Silverlight code and Script code at the same time, if the Silverlight debugger is selected JavaScript debugging is switched off.

  1. Go to the Project's Properties (Alt+Enter).
  2. For a Web Site Project: Select "Start Options". Or for a Web Appliction: Go to the Web tab and at the bottom you will see the Debuggers option.
  3. Check that the Silverlight checkbox is NOT ticked if you want to be able to debug JavaScript. (It is unfortunate that the UI here is not clear about this side effect.)
Mister Cook
  • 1,552
  • 1
  • 13
  • 26
  • 4
    I could kiss you. I'm trying to debug Javascript in an asp.net site, with a Silverlight project attached. Every time I tried to debug I got this weird cycle of popups asking me to attach a debugger then complaining the debugger was already attached. To be clear, go to the asp.net project in your solution and go to the project properties and open the Web tab. At the bottom there are checkboxes for the debuggers to use. Disabling the Silverlight debugger will make it so the javascript debugger works again. This needs to go in a wiki entry or something. – Dan Bailiff Jan 28 '11 at 16:17
  • @mister ok on mvc3/vs2010 I cannot see _Start Options_ under project properties – gideon Aug 19 '11 at 11:54
  • @Mister Cook, do you have any idea where this option is set in ASP.net / MVC 2 projects? – Yes - that Jake. Aug 31 '11 at 17:06
  • In a Web Application project go to Project Properties (Alt+Enter) | Web then its at the bottom (might need to scroll down) – Mister Cook Aug 31 '11 at 19:31
  • Thanks! This was driving me mad until I found this solution. PS: someone else selected the SL debugger thus I had no idea to look there. – Michael Hollywood Jun 07 '12 at 14:42
  • @MisterCook Web Application here. I follow your answer but still my breakpoints are not working. The only checked, check box is the ASP.NET and the SilverLight is uncheck. – KiRa Dec 23 '16 at 03:16
7

I was having the same issues. I was not able to get the IDE to even break at a breakpoint set inside a script tag. However when I added "debugger;" as the first line in the script tag was able to get the IDE to respond but then only to say that the disassebly was not availble.

However, I was able to click on the debug tools like "step into" and "step over". When I did this the IDE did progress into some of the external scripts that I am using (JQuery and Google Maps). So I took the JavaScript code block out of the view and put it into a separate .js file in the "Content" folder. Then I added a script tag to reference this new .js file (url = "/Content/Test.js").

It worked... a little bothersome that you have to go through this effort but maybe there is something to be said for JavaScript not being included directly in a view. I hope this is a bug they intend to fix.

Ryan Pedersen
  • 3,177
  • 27
  • 39
4

When debugging on IE, VS seems to add a folder called 'Script Documents' to the Solution Explorer. Inside this folder there is another folder called 'Windows Internet Explorer', and inside of it I see all the loaded js scripts and the (compiled) HTML file currently being displayed on IE. Setting breakpoints on the script tags in this HTML file does work for me.

clau137
  • 43
  • 1
  • 4
2

To resolve this go to the Project's Properties and select "Start Options". Then Check the Native Code Check Box. and Uncheck the Silverlight Checkbox because both options not works together.

1

CTRL+Alt+P (Attach to Process), select IE, select 'script' for the debugging type.

popester
  • 1,936
  • 9
  • 13
  • 2
    Thanks for the idea, but I get the same "There is no source code available for the current location" message that I got when I tried to launch with F5 and the "debugger" keyword. – Chris Farmer Oct 26 '09 at 16:58
  • Can you add a function in javascript, attach, and then create a new breakpoint based on the function name? – popester Oct 26 '09 at 18:36
0

As Ryan noted above, I moved my script to a seperate file under the Scripts folder. I also added debug into the name of the script so it became MyTestScript.debug.js. I included the script via a script tag and could set break points in the script file which the debugger hit.

frjames
  • 81
  • 1
  • 6
0

I have found that the Google Chrome devloper tool shows the JavaScript perfectly. In my case, I'm normally loading the script with jQuery's getScript function and execution of the code is typically by way of a jQuery callback upon loading a page or handling an event. With Visual Studio 2010, I frequently encountered the "No source" bug. Sad I need Chrome to debug JavaScript that is part of my Visual Studio project.

CraigAP
  • 11
0

Using a separate js file has its drawbacks. For instance, you can't use MVC helpers. Microsoft really needs to figure this one out.

Intellisense also does not work properly in script blocks on a view, even if you include the reference comments like this:

/// <reference path="/Scripts/jquery-1.6-vsdoc.js" />
/// <reference path="/Scripts/jquery-1.6.js" />

Intellisense works fine in the js file with this approach though.

Frank Hoffman
  • 887
  • 1
  • 11
  • 16