Solving the set Startup Projects bug in Visual Studio

This is a guest post by Albin Sunnanbo sharing how a mysterious Visual Studio problem made the Set Startup project command fail.

In one of our projects at work we had this mysterious problem with Visual Studio, both 2012 and 2013. It happened to some developers and some machines. When I got a new computer a while ago I was hit with this dreaded bug too. This is a story about how to use available clues to succeed with solving even the strangest problems.

When trying to set multiple startup projects in Visual Studio we right click solution, click Set StartUp Projects…
and expect the familiar dialog to pop up. But no, the menu disappears and then nothing happens. No dialog. Nothing.
If we click Properties instead we get an ugly dialog with the text “Object reference not set to an instance of an object.”

That poor dialog is pretty famous, it got something like a quarter of a million hits on Google. More than I’ll ever get.
Nothing on the top five Google pages seemed to help. We finally found a workaround. Uninstall NuGet package manager, set your startup projects, reinstall NuGet package manager. Not particularly elegant, but at least we could proceed with our regular work.

My Favourite Visual Studio Key Bindings

Working with code, there are some operations that are repeated many times every day, hour or even minute. Knowing (and creating) shortcut keys for those operations not only saves time, but keeps focus on the code. Reaching for the mouse might not take much longer time, but it switches the brain over to mouse-control mode and when doing that, some of the code context kept in mind is lost.

These are my favourite key bindings, both standard and non standard.

  • Global go to file/symbol on Ctrl+,. Brings up a small search box in the current windows for quick navigation to any source file, class or method in the solution. With VS2013 this got considerable better as it no longer brings up a large dialog box.
  • Go to current file in solution explorer on Ctrl+´, S. A somewhat awkward chord, but really useful to quickly get to the current file in the solution explorer. This is also the fastest and best way to do a rename of a class. Select the file in solution explorer, hit F2 to rename the file and Visual Studio will automatically prompt you about renaming the class and all references to it.
  • When coding, I usually split the window into two vertical tab groups, to view two code files at the same time. Most of the time one is the current test case and the other is the implementation (yes I’m a TDD fan). Two custom bindings that I use a lot with the split window are Ctrl+Alt+Left and Ctrl+Alt+Right to move the active windows to the previous or the next tab group.

Did I mention that I love TDD? That means that the key bindings related to running tests are among those I use most.

Speed up debugging using the DebuggerDisplayAttribute

Today’s post is written by guest blogger Albin Sunnanbo. He’s a great friend and source of inspiration and also one of the best developers I know. It was Albin that first introduced me to LINQ, EF Migrations and jQuery that I now use daily. In this post Albin shows how to use the [DebuggerDisplay] attributes to make debugging easier.

When debugging an application with lots of data, you often find yourself digging through long lists of data to find a specific item or verifying a specific property of one or more items. When using Data Tips, Watch or Quick Watch in Visual Studio you often find a pretty anonymous list of objects where you need to expand each item in the list until you find an object with the specific properties you need for your debugging scenario.

Here I have a LINQ2SQL context for my AdventureWorks demo database. I have a simple LINQ query for some products in the database and I want to find the product “Blade” that I previously created to verify that all properties was saved correctly to the database.

I brought up the Data Tip for my products list and start expanding/collapsing items. Quite boring work if you ask me.

Fortunately there is a better way: the DebuggerDisplayAttribute.

Software Development is a Job – Coding is a Passion

I'm Anders Abel, an independent systems architect and developer in Stockholm, Sweden.

profile for Anders Abel at Stack Overflow, Q&A for professional and enthusiast programmers

Code for most posts is available on my GitHub account.

Popular Posts



Powered by WordPress with the Passion for Coding theme.