Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2013 Breakpoint Issue with Razor

For some reason, I can't set a breakpoint in @functions when using Visual Studio 2013. Here's an example:

VS2013

However, the same kind of breakpoint works in Visual Studio 2012:

VS2012

  • If you move the @functions block up to the top of the razor page in VS2013 you can set a breakpoint in @functions once again.

  • You cannot set a breakpoint in @functions if the block is somewhere in the HTML.

Anyone know why? Maybe a bug? This is a big inconvenience if you're migrating an web app from MVC4 or earlier where @function blocks appear in the HTML.

like image 825
Brian Chavez Avatar asked Nov 09 '13 03:11

Brian Chavez


Video Answer


2 Answers

This seems like a known issue. See reported bug in MS Connect.

Description:

"After my upgrade to VS 2013, I am no longer able to debug javascript within MVC razor files. "

http://connect.microsoft.com/VisualStudio/feedback/details/807088/unable-to-debug-javascript-from-the-vs-2013-ide-unable-to-set-breakpoint

like image 55
Spock Avatar answered Oct 05 '22 04:10

Spock


I had all of the same issues with "This not a valid location for a breakpoint", and I also had no code highlighting or intellisense on any of the Razor code. None of the solutions I could find resolved it. Primarily because my issue was due to a really dumb oversight on my part, but just in case anyone finds themselves here and have made the same mistake, I thought I'd share it.

If you did not physically create the view yourself in Visual Studio, like if it was created with a NuGet package (Umbraco in my case), or if you opened an existing solution that isn't yours...The view may not be included in the project. You may see something like this enter image description here

Notice that the Homepage.cshtml file is in there and I can edit it, compile it, render it etc. But I could not insert a breakpoint anywhere. Right clicking on the file and Selecting "Include In Project" was the fix for me.

like image 33
hardba11 Avatar answered Oct 05 '22 02:10

hardba11