03 Jan 2013, 09:08

Can't find the IIS process when attaching debugger in visual studio?

TL;DR - If you can’t find your IIS process in Visual Studio’s debugger’s “Attach to Process” dialog, try visiting one of the sites that IIS serves in a web browser and then check the “Attach to Process” dialog again.

It took me a while to find the answer to this problem, so I thought I’d share. I’m running IIS on my local machine so I can debug my ASP.NET app while also using the app’s production URL instead of the “localhost” domain that the built-in Cassini server uses (just modify your hosts file to point production URLs to the web app on your local box). In order to debug, I go to Debug -> Attach to Process and then choose the process named w3wp.exe. I had been working like this successfully for a bit when one time I went to attach to the process and w3wp.exe wasn’t in the list. That was weird because when I looked in the IIS Manager it was clear that IIS was running. I tried opening and closing the attach to process dialog box several times, restarted Visual Studio, restarted IIS, and even rebooted my machine. Turns out the answer is simple: the IIS process doesn’t actually start running until one of its sites is accessed. So, all you have to do is visit one of the sites that IIS is serving in a web browser. I did this, went back to Visual Studio, went to attach my debugger to a process and there it was in the list: w3wp.exe!

This took awhile to figure out because I assumed the IIS process was already running, and the problem lay with Visual Studio, so my Google searches were all in that vein. I eventually found it on Stack Overflow: http://stackoverflow.com/questions/4313206/cannot-attach-debugger-to-w3wp.