Question

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.
Was it helpful?

Solution

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.)

OTHER TIPS

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.

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.

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.

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

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top