1

So what happens is this:

  1. Visual Studio breaks on (for me, as an end-user) valid Exception five async/await methods deep.
  2. This is behaviour that I like, because I can inspect state and see what is going on.
  3. Usually this line is marked yellow.
  4. When I press continue it will break again on every async/await in the upper stack. Marked as green, probably because the real stack is underneath, but that is my assumption.
  5. These last ones I want to prevent, as this means I have to press 5 times F5 to continue, while not giving me more information then I could have figured out by break 1.

Is there any way to prevent 4 without disabling 1?

Note: this is an ASP.NET MVC application and this can be i.e. a background Ajax call.

Dirk Boer
  • 8,522
  • 13
  • 63
  • 111
  • 1
    Did you ever find a good solution to this? Our "await chain" is even longer and with multiple requests breaking. So I currently have no other sensible way of escaping than dettaching the debugger – Simon Aug 24 '22 at 10:06
  • No I didn't find anything yet. I really don't understand why this is not a high priority and why it seems to affect so few people? It's driving me crazy - such a useless waste of time. – Dirk Boer Feb 13 '23 at 20:11
  • apparently I asked this question some other time - it has more upvotes, please upvote there too to get more attention: https://stackoverflow.com/questions/62705626/asp-net-core-do-not-break-on-await-next-invoke-green-breaks – Dirk Boer Feb 13 '23 at 20:12
  • 1
    and here is VS Feedback item someone else made: https://developercommunity.visualstudio.com/t/exception-dialog-pops-up-multiple-times-for-same-e/739876 – Dirk Boer Feb 13 '23 at 20:12

1 Answers1

0

It looks you are not catching the exception, and then it will bubble up through the call stack, regardless if you inspected it using the debugger or not. This is by design. There is no way to clear an exception that already occurred. The call stack is already in state of unwinding, and that is irreversible.

A solution might be to add a try catch with a conditional throw, like this:

try
{
    // code that may crash
}
catch
{
    // inspect the Exception here using VS
    var reThrow = true; // You can change reThrow to false while debugging
    if (reThrow) throw;
}
Peter B
  • 22,460
  • 5
  • 32
  • 69
  • 1
    Hi Peter, thanks for your answer! I'm fine with the way how to code works, I just don't want to press *Continue* five times on the same Exception break. Yes, I know there is a SQL Connection error - no need to remind me five times in all `await`s :) – Dirk Boer Sep 30 '19 at 13:12
  • 1
    If the *only* workaround is to add a try/catch I would not do this - as I don't want to compromise code over the debugging experience. In a way I'm looking for something like "never break on parent awaits". – Dirk Boer Sep 30 '19 at 13:12