Visual Studio's Attach to Process -dialog

Attaching the Visual Studio debugger to the right IIS worker process

This post was most recently updated on September 30th, 2022.

< 1 min read.

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 would 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

Time needed: 5 minutes

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. :)

mm
4 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments