Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2013 can't debug javascript in cshtml

I have an ASP.NET Web Application created with Visual Studio 2013. I am attempting to debug JavaScript in a CSHTML file. However, whenever I launch the webpage, any breakpoint turns into a red circle arrow and states, "The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line. Possible causes include: conditional compiliation, compilier optimizations, or the target architecture of this line is not supported by the current debugger code type."

Recently, the project was switched over to support MVC and RAZR, neither of which I know well, and this is exactly when this issue began. However, searching those have yielded results that don't fix my issue.

Web.config:

<compilation debug="true"...> 

I know I can debug JavaScript with Firebug or some other browser tool, but I would much rather stick with Visual Studio's debug as that is what I am used to.

like image 984
JuniorIncanter Avatar asked Dec 27 '13 21:12

JuniorIncanter


People also ask

How do I debug JavaScript in Cshtml?

Go to "Tools" then click on "JavaScript console". Run the application and insert values into the input fields then click on the "Addition" button. The cursor will then reach the debugger in the source tab under the JavaScript console window.

Can JavaScript be debugged?

But fortunately, all modern browsers have a built-in JavaScript debugger. Built-in debuggers can be turned on and off, forcing errors to be reported to the user. With a debugger, you can also set breakpoints (places where code execution can be stopped), and examine variables while the code is executing.


2 Answers

So, apparently this is a "known issue" that will be fixed as soon as possible. A temporary work around that works for "some" people is making sure any Javascript is in a separate file.

It is caused by having RAZR and Javascript in the same file and Visual Studio 2013 not being able to handle debugging in that instance.

like image 59
JuniorIncanter Avatar answered Sep 20 '22 08:09

JuniorIncanter


I don't know what your particular problem is, but if you want to force a debug breakpoint to always happen, add debugger; to the line that you want it to stop on, and it will stop. This is regardless of where the JS is located (in a .js file, .html, cshtml, etc.)

Here is a blog post about it:

http://sumitmaitra.wordpress.com/2013/12/11/quickbytes-visual-studio-2013-and-javascript-debugging/

I also agree that JS should go in a .js file (which I've never had a problem adding a break point in a .js file), but for quick prototyping, this is a solution you can use.

If that still doesn't work, you can always you the F12 tools

like image 27
joe_coolish Avatar answered Sep 20 '22 08:09

joe_coolish