Visual Studio's Attach to Process -dialog

Attaching the Visual Studio debugger to the right IIS worker process

Every now and then comes the time when you’d actually need to debug something, and then you’ll likely be using your Visual Studio to attach the debugger to one or more processes.

Using CKSDev to attach to all IIS worker processes (w3wp.exe), or if you don’t use CKSDev, just pressing ctrl+p and selecting the processes from the list, is often a good enough solution. However, sometimes that makes your dev box sluggish, or maybe catches exceptions from code you’re not wishing to debug at the time, and it’d be handier to just attach to the one process you actually need. But how to find out the right one? Chances are, you’ll be having 3-6 w3wp processes, and you can only deduce so much from the process id…

Solution

In these cases, appcmd is going to help you. It’s a simple command line utility that helps you find out the correct worker process. To use it, do the following:

  1. Run cmd as an administrator
  2. cd %systemroot%\system32\inetsrv
  3. appcmd list wp
  4. Fish out the process id from the output

And here you have it! You only need to attach to this single process to actually attach the debugger to the worker process running your custom code. Awesome!

PROTIP: Remember to select “Show processes from all users” in the “Attach to Process”-window – otherwise you’re not going to have much luck trying to locate the process you found in step 4 above. 🙂

The following two tabs change content below.

Antti K. Koskela

Solutions Architect / Escalations Engineer at Koskila / Norppandalotti Software / Valo Solutions
Antti Koskela is a proud digital native nomadic millenial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world. He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff. This is his personal professional (e.g. professional, but definitely personal) blog.

Let me know your thoughts!