0

When a client hits PUT endpoint on my Web API, and that endpoint produces any kind of exception, the whole Kestrel breaks down.

Visual Studio prints out:

The application is in break mode

Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code).

After I click on Continue Execution Application shuts down with message:

The program '[5364] dotnet.exe' has exited with code 0 (0x0).

The interesting thing is if I do the same thing with POST endpoint the exception gets caught in my ExceptionFilter or my ErrorHandlingMiddleware (as I've tried both with same success) and the application continues running as expected.

So this gets caught:

[HttpPost]
public async void Post(SomeModel model)
{
   throw new Exception();
}

While this shuts down the application:

[HttpPut]
public async void Put(SomeModel model)
{
   throw new Exception();
}   

I've tried clearing Nuget cache, deleting bin folder, running the application on Mac and on Windows, updating .net Core SDK and Runtime and probably few other things I found online for vaguely similar issues but without any success.

My application was running on Kestrel, .NET Core SDK 2.1.302, Runtime 2.1.2. I've since upgraded to .NET Core SDK 2.1.401, Runtime 2.1.3 but it made no difference. Same story running it on IIS Express

Milos
  • 1
  • 1
    What happens if you remove `async`? I expect ASP.NET Core is very unhappy about you throwing an exception that can't be later retrieved. (You should not be using `async void`, [FYI](https://msdn.microsoft.com/en-us/magazine/jj991977.aspx)). – Kirk Larkin Aug 24 '18 at 09:58
  • 2
    If you're going to use `async` try returning a `Task`, not `void`. – Brad Aug 24 '18 at 10:02
  • That's exactly the problem. I was looking at the all wrong places. Now ti seems silly. Thanks, Kirk and Brad. – Milos Aug 24 '18 at 10:46

0 Answers0