【问题标题】:VS2010 Debugger: The name 'VARIABLE_NAME' does not exist in the current contextVS2010 调试器:当前上下文中不存在名称“VARIABLE_NAME”
【发布时间】:2012-03-25 20:38:03
【问题描述】:

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

变量在作用域内。

对可能导致 tis 的原因或如何避免它的想法?

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

【问题讨论】:

  • 当您移动到下一条指令时,它是否显示为在范围内? AFAIK 您必须通过声明才能将其显示为“范围内”。
  • @Tudor:是的,通过声明后问题依旧。
  • 嗯,我可以在我自己的 VS 2010 中重现该问题。它必须是一个“功能”。 :)
  • @Tudor:我想你是对的。我添加了其他发现作为答案。希望它能帮助其他人避免挠头。

标签: visual-studio-2010 debugging


【解决方案1】:

正如 Tudor 所说,这似乎是 VS 2010 SP1 的一个限制。

我发现操作数直到被代码实际使用后才对调试器可见,而不仅仅是在赋值点之后。

具体来说:

Debug.WriteLine(operand);

正确打印到控制台。

另外,一旦 operand 被 Linq 语句的 where 子句求值,Quick Watch 和即时窗口就突然知道了。

【讨论】:

  • 我试过这个答案,但我仍然遇到同样的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-02
  • 2014-04-22
  • 2017-06-17
  • 2015-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多