调试程序在VS 2012中跳过最新的签入代码 - 与VS 2010一起使用

时间:2013-02-12 23:26:14

标签: c# debugging visual-studio-2012 mstest

编辑:我刚刚尝试使用VS 2010,但问题没有发生。这个问题只发生在VS 2012上。这真的是一个错误吗?这也发生在我的两台独立笔记本电脑上,甚至在朋友的笔记本电脑上(刚刚获得最新代码)。

首先,问题的截图。这个方法都是 new 代码。

enter image description here

调试器正在从我最近的签入中跳过代码。下面的代码中的注释解释了我调试此方法时发生的情况。所以真的没有必要尝试理解代码;只是注意到正在跳过代码行。如果您认为代码与正在调试的程序集不匹配,请耐心等待。您将看到调试器识别新代码的位置,而不是现有代码。在删除磁盘上的代码并再次获取最新信息之后,这种行为发生在两台不同的笔记本电脑上。每个注释都会告诉您调试器是否命中一行。

[TestMethod()]
[DeploymentItem("PrestoCommon.dll")]
public void ApplicationShouldBeInstalledTest_UseCase9()
{
    // Debugger hits this line
    ApplicationServer appServerAccessor = new ApplicationServer();

    // Debugger does not hit these next two lines
    PrivateObject privateObject = new PrivateObject(appServerAccessor);
    ApplicationServer appServer = ApplicationServerLogic.GetByName("server10");

    // Debugger hits this line. Weirdness: both objects are null, and after this line runs,
    // appServerAccessor is no longer null.
    appServerAccessor.Id = appServer.Id;

    // Skips this line
    ApplicationWithOverrideVariableGroup appWithValidGroup = appServer.ApplicationsWithOverrideGroup[0];

    // Debugger hits this line, but F11 doesn't take me into the method.
    appWithValidGroup.CustomVariableGroup = CustomVariableGroupLogic.GetById("CustomVariableGroups/4");

    // Skips this line
    Assert.AreEqual(true, true);
}

反汇编只显示实际被击中的代码行。

enter image description here

现在,看看这个。如果我添加一行新代码,调试器会识别它,并且其他代码行会发生变化,只要调试器能够识别。在方法中,第二行代码是新的。

[TestMethod()]
[DeploymentItem("PrestoCommon.dll")]
public void ApplicationShouldBeInstalledTest_UseCase9()
{
    // Debugger hits this line
    ApplicationServer appServerAccessor = new ApplicationServer();

    // New line. It's recognized by the debugger, and it shows up in the disassembly.
    if (DateTime.Now > DateTime.Now.AddHours(1)) { return; }

    // Debugger does not hit these next two lines
    PrivateObject privateObject = new PrivateObject(appServerAccessor);
    ApplicationServer appServer = ApplicationServerLogic.GetByName("server10");  // Gets hit now.

    // Debugger hits this line. Weirdness: both objects are null, and after this line runs,
    // appServerAccessor is no longer null.
    appServerAccessor.Id = appServer.Id;  // No longer gets hit.

    // Skips this line (now it's getting hit)
    ApplicationWithOverrideVariableGroup appWithValidGroup = appServer.ApplicationsWithOverrideGroup[0];

    // Debugger hits this line, but F11 doesn't take me into the method. Now this gets skipped.
    appWithValidGroup.CustomVariableGroup = CustomVariableGroupLogic.GetById("CustomVariableGroups/4");

    // Skips this line. Still skipped.
    Assert.AreEqual(true, true);
}

这是反汇编的部分快照,显示了新的代码行:

enter image description here

这怎么可能发生?

增加了奇怪性,有一点甚至还没有回复:

if (DateTime.Now > DateTime.Now.AddDays(1)) { return; }

我尝试过的事情:
- 从硬盘驱动器中删除源代码并强制获取最新信息 - 修复VS 2012
- 做一些VS clean-up
- 使用VS 2010,更改密码,办理登机手续,获取VS 2012的最新信息 - 重新启动
- 其他(不记得所有)

1 个答案:

答案 0 :(得分:4)

这似乎是针对单元测试的。在VS 2012中:

  • 测试>测试设置
  • 打开所选的测试设置文件
  • 数据和诊断>取消选择代码覆盖率(Visual Studio 2010)
  • 应用

注意,我有访问源代码的优势,我下载了Presto(http://presto.codeplex.com/)。