Monodevelop Debugger evaluates temp variable as "null" in for loop when clearly not null

Whenever I’m using Monodevelop-Unity to step through code in a loop (aka “foreach”), if I try to add the temporary variable to the watchlist, it always evaluates to null, even when the value is clearly not null (and the code executes to represent this).

For example:

	for (var firingShip : GameObject in firingFleetArray) {
		if (firingShip) {

If I add firingShip to the Watch list, it always displays as null. But at the same time if I add firingFleetArray to the Watch list it will display its members correctly (none of which are null). Additionally, I can Step Into the code and get to the Fire() function, even though the code should skip over it if firingShip were actually null.

I’ve googled everywhere for something like this but can’t find anything. Is something messed-up about my installation, or am I missing some obvious setting?

This can happen if the variable you are watching is an object derived from UnityObject. If the “name” field isn’t set it will be null, and UnitObject’s ToString method will unhelpfully return that as the value of the variable.

This also seems to cause MonoDevelop to get confused about the fact that the variable has a real value in some cases. I fixed it in my case by not having a couple of classes derive from UnityObject.