Web API控制器中无法击中断点 [英] Cant hit breakpoint in web api controller

查看:318
本文介绍了Web API控制器中无法击中断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试调试此代码时:

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);
        }

无法点击此行:

   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.

推荐答案

尝试删除操作的异步部分.这不是永久性的解决方案,但是它可以帮助您进行调试.我建议的另一件事是在操作中尝试捕获代码.您的反序列化可能失败,并引发异常,无论出于何种原因,调试器都无法捕获.

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);
    }

这篇关于Web API控制器中无法击中断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆