Web API in MVC Project isn’t hitting breakpoints (“symbols not loaded”)

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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

Method 3

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.

Method 4

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.

Method 5

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.

Method 6

This solved my problem:

  • CloseExit 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

Method 7

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.

Method 8

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.

Method 9

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x