Introduction
Prevent Visual Studio crashes when working with MVC web applications.
Background
Recently, I was trying to debug a MVC 5 web application in Visual Studio 2012. However, every time I would try to debug it, Visual Studio would crash. If I put the build into release mode, then I could run the application (but not debug it). I was using IIS7 to host the site in my local development environment. I realized that the issue happened when I was working on a production issue and it came to me that I had been experimenting with running the application pool as a web garden, which is to say more than 1 worker process.
The Cause
The cause is, the best I can determine the fact that I had the application pool set to have 7 worker processes and had several users logged into the site. When debugging the web application, Visual Studio has to attach to the work process. When there is more than one running, Visual Studio seems to not know which one to attach to, or it seems to attach to the wrong one which results in an error condition that causes Visual Studio to crash.
The Solution
To resolve the issue, I went into IIS 7, found the application pool in question under application pools and went into advanced properties. Find the setting for Maximum worker processes. In my case, I had it set to 7. I set it back to 1, restarted the application pool and went into Debug mode and voila! Debugging successful!