简体   繁体   中英

Visual Studio 2012 - Breakpoints in Razor view files (“.cshtml”) not being loaded

When setting a break point in a razor view (".cshtml") the circle which is normally red turns to a red hollow circle when the debugger is started. When hovering over the hollow circle it displays the following:

The breakpoint will not currently be hit. No symbols have been loaded for this document

It's only razor view files, with normal ".cs" files there are no problems.

There are a lot of other questions which have proposed solutions for the same "error" message as above but none has actually worked. What I have tried:

  • Cleaning the solution
  • Ensuring that in the properties -> Web window, under the "debugger" section that ASP.NET is checked
  • Ensuring that in the properties -> Build window, that both Define DEBUG and TRACE are checked and in the output section of the same window, clicking the advanced button, the debug info is set to "Full"
  • Rebuilding everything a million times.
  • Using VS with administrator rights (I do that normally anyway)
  • Restarting system
  • Restarting site in IIS
  • Ensuring that the Active Solution Configuration is set to Debug
  • Checked that in the web.config file, compilation debug="true"

Edit: I'm referring to the razor code of course, not html or even javascript. Eg setting a break point in a foreach loop in razor

Edit2 : I'm able to step through the razor code if I set a breakpoint in a controller, as the the debugger will go through the view before being "done". I'm still not able to actually set breakpoints in razor view files though. The hollow circle is still showing and it won't get hit.

Edit3 : Killing the "IIS Working Process" which points to w3wp.exe temporary solved the problem. I was able to debug razor views again. A few hours later, the same problem again.

我发现在.cshtml文件上切换Build Action = Content / Compile (在属性窗口中)(中间有一个构建) 让我再次设置断点

This is what your looking for.

You need to compile your views at compile time not asp.net runtime.

https://stackoverflow.com/a/16052993/955831

Remember that views are actually compiled when you request the page (by default).

This means when you set a breakpoint in a view:

  1. It shows the "No Symbols" error. This just means the view isn't compiled yet.
  2. It shows the breakpoint fine. This just means that it found SOME compiled version of the page. Like the LAST working version...

So basically its not meaningful information to look at what it says when you mouseover the breakpoint in a view (at least in this regard)

If you are trying to debug this page, then you have a problem . Look at what the debugger is outputting to your BROWSER instead and fix that first. I think we'll be surprised about how many people are going to facepalm at this.

在web.config文件中,检查下面的debug =“true”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM