Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant hit breakpoint in web api controller

When i try to debug this code :

 // POST: api/Events
    [HttpPost]
    public async Task<IActionResult> PostEvent([FromBody] object savedEvent)
    {

        Event addedEvent = JsonConvert.DeserializeObject<Event>(savedEvent.ToString());

        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

Cant hit this line :

   Event addedEvent = JsonConvert.DeserializeObject<Event>(savedEvent.ToString());

Debuger reacts like i hit continue but code past doesnt execute. Im really confused. Thanks for your help.

like image 592
Mind Tha Gap Avatar asked Jan 21 '17 15:01

Mind Tha Gap


People also ask

How do I hit a breakpoint in postman in Visual Studio?

Just start your API in debug mode, and let a Postman tab/app opened. If you have a breakpoint set in your code, when you send a request from Postman, it you hit that breakpoint and you can start debugging.

How do you activate a breakpoint?

To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.


Video Answer


3 Answers

Couple of things you may try

1) Make sure you are running in Debug mode (not in release)

Like this

2) Make sure you are running the latest code with all symbols loaded (hovering over the break point can give you extra information of why its disabled)

like image 191
Ali Baig Avatar answered Oct 23 '22 03:10

Ali Baig


Try removing the async part of the action. This isn't a permanent solution, but it might help you debug. Another thing I'd suggest is to put a try catch around the code in your action. It's possible your deserialization is failing and throwing an exception that for whatever reason, the debugger isn't catching.

// POST: api/Events
[HttpPost]
public ActionResult PostEvent([FromBody] object savedEvent)
{

    Event addedEvent = JsonConvert.DeserializeObject<Event>(savedEvent.ToString());

    if (!ModelState.IsValid)
    {
        return BadRequest(ModelState);
    }
like image 3
Brendan Long Avatar answered Oct 23 '22 04:10

Brendan Long


You are probably running your application in the "Release" mode instead of "Debug".

You can't set breakpoints in "Release mode" (most of the times).

What is in a symbol (.pdb) file? The exact contents of symbol files will vary from language to language and based on your compiler settings, but at a very high level they are the record of how the compiler turned your source code into machine code that the processor executes.

Source: https://blogs.msdn.microsoft.com/devops/2015/01/05/understanding-symbol-files-and-visual-studios-symbol-settings/

like image 3
Tadej Avatar answered Oct 23 '22 05:10

Tadej