The evil suo file - fighting and winning with Visual Studio

There is an important trick I learned years ago that I always refer to as “The evil suo file” that I thought was more common knowledge than I guess it is. I realized this when I had to show it to my esteemed colleague Michele and she had never heard of it. It has happened to me dozens and dozens of times and dates back to VS 2003 or VS 2002 was when I first learned it, source long forgotten.

Here is the deal. If you are debugging and you are staring at the code and have something weird happening in Visual Studio. If you can convince yourself there is no way this could be happening, the code just can’t/shouldn’t be doing what you are seeing. In Michele’s case we were stepping through the code, watching one line of code setting a property, seeing that no other code set the property through a breakpoint in the setter, and then a line of code read the property and it was a different value than last set.

One thing you should try is to close VS, delete the suo file in the solution folder, and open the solution and try it again. Like I said, dozens and dozens of times, this has made something really squirrely go away for me.

My general fighting and winning with VS is this. Convince myself that I am not just trying to blame VS for something wrong with my code. VS is a wonderful, powerful, amazing tool that makes our lives SO much easier than they used to be.

1) If VS is doing something weird, close and reopen, and try again.

2) If VS is still doing something weird, close delete suo, and reopen and try again.

3) If VS is still doing something weird, close and Clean Sources (delete suo and all obj/bin folders), reopenand try again.

4) If VS is complaining about references to do with a project, remove it from the solution and add it back in. This happened with a customer this week where VS was insisting we were trying to add a circular reference when trying to add a ref to a particular project in the solution, and it was just lying. Removing it from the solution and adding it back in (and of course patching all the removed references from all the dependent project) fixed it.

5) If you have any add-ins, go to Tools > Add in manager and uncheck the startup box for all add ins. Close and reopen studio and see if the problem goes away. If so you may have a problematic add-in.

If those don’t do it, it was probably your code in the first place.

Again, VS is an awesome dev environment. We really have it good. However, it is not perfect like most software. Don’t waste hours chasing goblins in your code when it may just be a touch of gas in the VS belly.