Apr 272018
 April 27, 2018  Posted by at 5:00 am .NET Core, ASP  Add comments

I have a bad habit of using the NuGet Package Manager Console in Visual Studio as a PoSh CLI (which it sort of is), and today I ran ‘dotnet run’. And then I was unable to kill the session. The console was unresponsive, and so was the NuGet browser. Arghhh….ops. I restarted Visual Studio, and that got the console working again, but my port was taken and Kestrel spinning.

PowerShell has cmdlets for most things you could do in the good ol’ commandline, and there is one for working with TCP connection.

This will list all the connections:


and if you had some filtering with the parameters such as the port you can narrow down the result

Get-NetTCPConnection -Port 1106

The result is a list, and if you wrap the result in parenthesizes you can enumerate the items and pull out specific properties without piping+iteration

(Get-NetTCPConnection -LocalPort 1106).OwningProcess

This gave me the PID (process ID), and with that I could run

$rsult = (Get-NetTCPConnection -LocalPort 1106).OwningProcess[0]

Kill -Id $result

Voila. Process dead.

  One Response to “ASP.NET Core: killing a Kestrel session that refuses to die”

  1. This is a bit scary. I tried this, and got “4” as the process Id. Get-Process -Id 4 gives me the “System” process. I have ran the servers with Start-Process, not via Visual Studio, could that be the problem?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



What is 5 + 5 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)