Javascript breakpoint not work in Visual Studio 2019 asp.net application
Asked Answered
A

6

16

I recently upgraded from VS 2017 to VS 2019.

In VS 2017, when running an asp.net application locally, using Chrome, I could put a breakpoint in javascript code and the debugger would stop on the breakpoint. This no longer works in Visual Studio 2019.

What do I need to do to enable javascript debugging in Visual Studio 2019 using Chrome? I would like to be able to put breakpoints in javascript files and have them hit.

Here is my setup.

  1. I've enabled Javascript debugging. enter image description here

  2. I put a breakpoint in my Javscript code. This breakpoint is in a *.js file (not inside a Razor view).

enter image description here

  1. The breakpoint is ignored. Visual Studio very courteously shows me a tooltip telling me the breakpoint will be ignored.

enter image description here

Autoeroticism answered 1/11, 2019 at 13:55 Comment(4)
I guess it will work if you use chrome or internet explorerFilaria
@TAHASULTANTEMURI it is not working, that is the problem. I'm using Chrome (I have to use Chrome).Autoeroticism
The solution for me was: #71698032Deannadeanne
Double check your code - my solution was the js code was not compiling correctly / being included correctly. To be clear .js files CAN be debugged but they have to be found and compiled.Platinumblond
F
2

It should work in VS2019+Chrome.(I just checked this in several machines)

This is not one issue can be resolved directly since many factors can cause this behavior, you can follow suggestions below to check if it helps:

1.Update your VS2019 to latest 16.3.7, update your chrome browser to latest 78.0.3904.87

2.Delete the bin and obj folders in your project directory => then close and restart VS => open that project and do a clean rebuild

3.Make sure you're in debug project mode, right-click your web project=>Set as StartUp project

Also, sometimes we need to wait for several seconds before the debug session starts successfully.(I once met same popup, then after several seconds it disappeared and everything worked)

Hope it helps :)

Fromma answered 4/11, 2019 at 7:44 Comment(7)
None of the suggestions above seem to work for me. VS is v16.6.4. Chrome is v84. "Enable JavaScript debugging for ASP.NET" is checked. My JS is in CSHTML files. I get a similar message in VS: "The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line." Have tried deleting bin and obj folders. Also is the correct Startup Project. Anyone have success with this?Hasen
And when the JS code is in a JS file, the debug point stays the normal red (with no warning message), but is never hit. Even with a simple alert("Hello, world!"), I see the alert, but the breakpoint is not hit.Hasen
So, Edge seems to work just fine, but not Chrome. So I guess Edge it is when JS debugging is necessary.Hasen
Cardi DeMonaco, I found that when the breakpoint is being ignored in a .js file I must close VS, delete the bin and obj folders for the solution, reopen the solution and rebuild all, then start the debugger, revisit the page in question and do a Ctrl-F5 to reload the javascript. When I go through those steps it usually starts finding the breakpoint again. I don't know about putting break points in cshtml files though.Autoeroticism
@CardiDeMonacoJr - Edge has the same problem for me with a slightly different message. Instead of "Breakpoint set but not yet bound" it just says "Unbound breakpoint"Translator
Nothing has worked for me so far. Using Internet Explorer as well as Chrome with ASP.NET Website and VS 2019. #66609543 Pls help.Indohittite
A half-baked VS version is on the pipe line at the moment, there seems to be no fix to this thing yet. Very disappointed again with Microsoft Visual Studio. I tried everything suggested but nothing works, no hope on this one yet.Culex
A
1

Besides enabling JavaScript debugging in Visual Studio, please ensure that minification is off. (Turn off bundling/minification while debugging in WebForms)

Ablaze answered 1/7, 2021 at 14:47 Comment(1)
If using .Net Core with Ligershark WebOptimizer you need to turn off minification in dev mode in startup.cs. e.g. services.AddWebOptimizer(minifyJavaScript: false, minifyCss: false);Kutchins
A
1

If your page contains Razor syntax, the breakpoints won't work.

Instead add the debugger; statement into the script as a breakpoint.

Then again, the debugger statement had failed to work earlier this year. It only works at top level, means before the page is completely rendered. It will not work if I put the debugger statement into $(document).ready()

So my work around now is to put my javascript in a separate .js file without any Razor syntax.

Aldoaldol answered 7/9, 2021 at 5:18 Comment(0)
C
1

The good old console.log works for me as nothing suggested as above answers are working at all. Anyway it is what it is amidst the frustration for VS, nothing new about that.

Culex answered 16/9, 2021 at 1:3 Comment(0)
K
1

If your Javascript is in a Razor file it will not work.

I have been struggling with this for ages and getting by with console.log. But just now I moved the js into an external file and bingo it works.

I am using latest VS 16.11.5 and Chrome in a .Net 5 project with Razor pages.

Kutchins answered 1/11, 2021 at 8:58 Comment(1)
I noticed in my original post that my javascript is in a *.js file, not in a Razor view, and yet the problem still occurred.Autoeroticism
B
0

I have noticed that if I open a URL from within Javascript in the following manner:

window.open("url");

It opens in a new tab and no breakpoints will be hit in the javascript that loads for the new browser window. Nor will "debugger" work. However, if you do NOT open in a new tab, but use:

window.open("url", "_self");

It opens in the same window, and breakpoints will work. Something about the execution context of the browser in a new tab I think. I hope this helps.

Bitters answered 19/7, 2023 at 17:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.