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:
What I tried:
Questions:
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
All of these leads to improved scalability of our application. These two keywords – async and await – play a key role in asynchronous programming in ASP.NET Core. We use the async keyword in the method declaration and its purpose is to enable the await keyword within that method.
These two keywords – async and await – play a key role in asynchronous programming in ASP.NET Core. We use the async keyword in the method declaration and its purpose is to enable the await keyword within that method. So yes, you can’t use the await keyword without previously adding the async keyword in the method declaration.
The one thing that didn't 'just work' was the async requirement of ASP.NET Core's output generation. The old code - which originally was written for .NET 1.1 and then moved through generations of .NET through 4.5+ - didn't use async output, so all the code at the middleware API 'seam' needed to be changed to async.
This was made even more insidious by the fact that the original code in .NET Core 2.1 worked just fine even without the await call, meaning this error cropped up a year or so after I had originally ported the code and had been running it successfully for that long.
Add a Module Name
condition in the Exception Settings
window so you won’t break on any exceptions thrown from others.
In my case, I set Module Name = "HomeController.cs" to enable exceptions here.
Screenshot of Test
It will break here and press F5
to end debug as we expect.
When you remove conditions of exception setting, it will recover as you.
The microsoft doc about conditions to an exception
Break on Exceptions Thrown only from Specific Modules in Visual Studio 2017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With