VS2010调试器:当前上下文中不存在名称“VARIABLE_NAME”

时间:2012-03-25 20:38:03

标签: visual-studio-2010 debugging

调试VS2010 SP1中的迭代器方法(使用DEBUG设置......没有编译器优化),我的变量之一操作数,“在当前上下文中不存在”,根据Quick Watch的说法即时窗口(如果我将鼠标悬停在变量上,我也不会弹出一个弹出窗口。)

变量在范围内。

关于可能导致什么或如何避免它的想法?

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 */
        };
    }
}

1 个答案:

答案 0 :(得分:0)

正如都铎所说,这似乎是对VS 2010 SP1的限制。

我发现操作数在代码实际使用之前不会对调试器可见,而不仅仅是超出赋值点。

具体做法是:

Debug.WriteLine(operand);

正确打印到控制台。

此外,一旦操作数由Linq语句的 where 子句进行评估,Quick Watch和Immediate Window就会突然了解它。