Debugging tip: But that can’t happen!! Ah, but it did. Ensure you are looking at the right object – level 300

Debugging can be easy or hard.  It’s easy if you have an easily reproducible error.  This morning I wrestled a bug where a screen just stopped showing data.  Nothing.  Zilch.

When I debugged through, I watched every piece of data get properly set to labels in my Winforms view that were visible, but the screen shows up without the data!! What gives?

Ultimately, I was looking at the wrong instance of my screen/view. 

Here’s a debugging tip to use if you watch the code executing properly but it still doesn’t work in the end:

Make sure you are looking at the right object.

In the debugger, set a breakpoint in the constructor and ensure you are watching the right instance.  In the immediate window, use the hashcode to track the instance:


This way, you can clearly identify the object.