Asp.net Core - do not break on await next.Invoke() ("green" breaks)

Viewed 783

Recently I switched to ASP.NET Core and mainly I love it!

There is one annoying part though - when I have an Exception this bubbles up through all the parts of await next.Invoke() in my whole application. That means every custom Middleware or filters that use async/await.

This means I have to press continue / F5 about 8 times every time an Exception occurs. Especially while working on tricky code this is super annoying and a big waste of time and mental energy.

See this example below:

Annoying breaks

What I tried:

  • enabled Just my Code - does not solve - as this is happening in my code.
  • disable this type of exception in the Exception Settings - this does not solve my problem, because the first (yellow) I actually need.
  • fill my whole application with [DebuggerNonUserCode] - also something that I don't like to do - as there might be legit exceptions not related to some deeper child exceptions.
  • see for more information this question

Questions:

  • As Visual Studio seems to be able to differentiate between these two Exceptions (yellow and green) - is it possible to not break at all at the "green" Exceptions?
  • How is everyone else handling this? Or do most people not have 5+ await next.Invoke() in their code?
  • Any other workarounds?

UPDATE The workaround of @MichelleWang works with specific cases, but it has a lot of configuration and maintenance if you work with a lot of different or complicated projects. Usually the async / awaits are scattered over a lot of different classes. Some filters, some base projectcode, some domain code, etc.

In a way VS already distinguishes between these two types of breaks - how to just break on yellow in general?

UPDATE

Found an existing feature request - please help and upvote there:

https://developercommunity.visualstudio.com/content/idea/739876/exception-dialog-pops-up-multiple-times-for-same-e.html

1 Answers

Add a Module Name condition in the Exception Settings window so you won’t break on any exceptions thrown from others.

  • Open Debug->Windows->Exception Settings
  • Click on an exception type or category
  • Right click on that exception and choose “Edit Conditions” Or click the blue edit pencil in the toolbar

enter image description here

In my case, I set Module Name = "HomeController.cs" to enable exceptions here. enter image description here

enter image description here

Screenshot of Test

It will break here and press F5 to end debug as we expect. enter image description here

When you remove conditions of exception setting, it will recover as you. enter image description here


The microsoft doc about conditions to an exception

Break on Exceptions Thrown only from Specific Modules in Visual Studio 2017

Related