13

I have an ASP.NET MVC project, with an ASP.NET web api defined as an area in this project. So the structure is the following:

MVC Web
   Controllers
   Views
   Areas
     API (web API)
       Controllers

The app works as expected. However, I am having an issue with debugging. I can put a debugger in the MVC controller, and it works as expected. I cannot put a breakpoint in the web API controller, as I get "the breakpoint will not currently be hit. No symbols have been loaded for this document." I've been in the throes of it for some time, so it's probably a simple fix but I cannot figure it out. Any ideas why I'm getting this problem with web API controllers, when I can debug an MVC controller?

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • I often find this when my assemblies I am trying to use are not compiling as I expected. Make sure you are compiling all your classlibs and doing rebuild all. HTH's (BTW, I can hit my webapi controller debug with no issue so it's not fundamentally a problem I think) – Peter Kellner Jan 01 '13 at 06:55
  • 1
    If you're using IIS Express, try shutting it down and letting VS fire it back up after you "Rebuild" your solution. – anAgent Jan 02 '13 at 23:30
  • 4
    For me, I had this problem when the WebApi project was not set as the startup project for the solution. Making my project the startup one solved the problem. – NickBeaugié Oct 14 '13 at 16:39

10 Answers10

27

Until you find a permanent solution you can use the method System.Diagnostics.Debugger.Break() to force a break to occur on that line - just like a breakpoint:

public ActionResult IndexCheckInOut(string providerKey, DateTime? date = null)
{
    System.Diagnostics.Debugger.Break();   
    return View("Index");
}

Here are some links to articles that might help you find a more permanent solution:

The breakpoint will not currently be hit

Stepping into ASP.NET MVC source code with Visual Studio debugger

Luis Perez
  • 27,650
  • 10
  • 79
  • 80
Sampath
  • 63,341
  • 64
  • 307
  • 441
5

Possible solution: I had forgotten that I was previously doing some remote debugging and had set debug symbols to be loaded from a UNC path instead of the Microsoft Symbol Servers.

To fix this head to: Tools -> Options -> Debugging -> Symbols -> Make sure 'Microsoft Symbol Servers' is checked.

I also found this issue from creating a new Solution Configuration and not basing it on any existing configuration, such as the DEBUG configuration. That caused Debug Info to be set to none.

To fix this: Right-click your project -> Properties -> Build -> Make sure your faulty Solution Configuration is set -> click Advanced -> change Debug Info to full.

Nexaspx
  • 371
  • 4
  • 20
hvaughan3
  • 10,955
  • 5
  • 56
  • 76
5

For me it worked out to just stop IIS and restart Visual Studio. Definitely worth a try before further investigation.

FrKunze
  • 190
  • 3
  • 8
3

Open:

Tools - Options - Debugging - General

Select:

  • Enable .NET Framework source stepping

  • Enable source server support (all options selected)

Open:

Tools - Options - Symbol

Select Microsoft Symbol Servers

Click Load All Symbols

Rebuild the project.

Select:

Clean

Rebuild

Rebuild solution and try again.

live-love
  • 48,840
  • 22
  • 240
  • 204
1

Just had this issue myself and was tearing my hair out for about an hour until I realised Visual Studio had mysteriously switched to run the project in 'Release' mode. Switching back to 'Debug' mode and rebuilding sorted me out.

Probably a very niche answer to this problem, but hopefully this helps somebody.

grimdog_john
  • 675
  • 1
  • 7
  • 15
0

This solved my problem:

  • Close\Exit from all instances of IIS Express in the system tray (beside the Windows clock).
  • Delete bin and obj folders in your project directory
  • Restart Visual Studio
  • Run it again

enter image description here

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
0

I had the same issue but mine was related to the addition of a config Transform. Go to Build > Configuration Manager under Active Solution Configuration make sure you have Debug selected.

0

My problem was the following

I had created a virtual directory in my IIS and use that name in my start URL link like http://WebAPI/swagger/ui/index (My symbols where not loaded with all the above steps)

  1. Use IIS Express
  2. Deleted the website from IIS Manager called WebAPI
  3. Start URL I changed back to is http://localhost:59788/swagger/ui/index (Default port from visual studio)

Now all my symbols are loaded.

Dongolo Jeno
  • 414
  • 6
  • 8
0

if your debug worked and suddenly stopped working, the most common reason in my experience is problem in the IIS.

  1. check that project->properties -> project URL is correct,
  2. use IISReset to reset IIS
Citizen-Dror
  • 843
  • 9
  • 17
0

app.MapControllers() was missing from program.cs

I only stumbled across this on a medium article, fortunately!!

(I’m using .net 7.0)

It was very odd because my first get-all sales were being returned, that only returned a simple entity type though!

Now I can clearly see 500 errors. For example, the AdventureWorks 2017 SalesOrderDetail table requires two integers for its primary key!

Mahyar Mottaghi Zadeh
  • 1,178
  • 6
  • 18
  • 31