Debugging an iterator method in VS2010 SP1 (with DEBUG settings… no compiler optimization), one of my variables, operand, “does not exist in the current context” according to Quick Watch in the Immediate Window (I also do not get a popup if I mouse over the variable).
The variable is in scope.
Thoughts on what might be causing tis or how to avoid it?
private IEnumerable<Answer> CreateVirtualFormulaAnswers(Question question, List<Answer> answers)
{
string[] formulaParts = question.Formula.Split(FORMULA_SPLIT, StringSplitOptions.None);
string formula = formulaParts[0].Trim();
if (formulaParts.Length != 2) throw new Exception("Formula format is incorrect: " + question.Formula);
// At this point:
// formulaParts.Length = 2
// formulaParts has a non-null string at each index
// Mouse over of "op" in VS2010 debugger does not show any popup
// Quick watch and immediate window both state: "The name 'operand' does not exist in the current context"
string operand = formulaParts[1].Trim();
string answerText = (from a in answers where a.QuestionCode == op select a.Text).SingleOrDefault();
if (answerText != null)
{
yield return new Answer()
{
/* Initialization code here based on formula */
};
}
}
This seems to be, as Tudor suggests, a limitation of VS 2010 SP1.
I found that operand doesn’t become visible to the debugger until it is actually used by code, not just past the point of assignment.
Specifically:
printed correctly to the console.
Also, once operand was evaluated by the where clause of the Linq statement, Quick Watch and the Immediate Window suddenly learned about it.