Tag Archives: vs2010

VS2012 Debugger Jumping Around For VS2010 Unit Tests

One of the big selling points for Visual Studio 2012 to early adopters is that you can work seamlessly with Visual Studio 2010 projects and 2010 users. I’ve found this to be largely true and have only run into one significant problem. It’s related to debugging unit tests, and it’s a real head-scratcher. The symptom is that everything is hunky-dory in VS2010: you hit breakpoints, step through code, and everything works just like you’d expect. However, you get consistent weirdness in VS2012. You’ll stop on a breakpoint and try to step over a single line of code, but it’ll jump two lines ahead. The contents of variables will be inconsistent between the code and the next line to be executed. It’s really confusing.

From what I can gather from this forum post (you might want to skip to the bottom for solutions), the problem is due to how VS2010 instruments assemblies to measure code coverage. The solution that I found to work was to manually edit and remove the AgentRule section from the local.testsettings file.

I suspect the problem could also be solved by disabling code coverage from within VS2010 and then re-enabling it in VS2012. One of my favorite things about VS2012 is that you don’t need to manually instrument an assembly to analyze code coverage. Since VS2010 does need this, there is a special setting in vs2012 that can be enabled to maintain backward compatibility.


So, just to recap, I suggest the following two solutions if you’re getting debugger jump-arounds while debugging VS2010 unit tests in VS2012:

  1. In Visual Studio 2010, disable code coverage. Then, in Visual Studio 2012, enable the Code Coverage (Visual Studio 2010) setting and select the assemblies to instrument.
  2. If solution #1 fails, edit your .testsettings file manually and remove the AgentRule section.

For either of the solutions above, be sure to clean your output directory. Make sure to get rid of all DLLs and PDBs.


Unit Test Debug Wonkiness in Visual Studio 2012

Our team has started rolling out Visual Studio 2012, and it’s been largely issue-free. In fact, the only issue that we’ve run into is a weird one: the debugger gets screwed up while debugging unit tests. What I mean by “messed up” is that you step over a line, and it jumps down several lines, variables don’t get set; you know, wonkiness!

Luckily, we were able to find this MSDN forum post, which describes our problem and how to solve it.

The problem seems to be related to the solution test settings file. The solutions presented in the forum are to remove the old test settings file or to remove the AgentRule section from the file. We tried these, and it worked for us, too.

Looking a little deeper, we found that the issue occurred when debugging unit tests–running them worked fine–in VS2012 for a solution created in VS2010 with code coverage enabled. Even with all that, the issue did not occur regularly. It worked fine on my machine, but not on my colleague’s. We removed the old test settings file but re-enabled code coverage 2010-style from within 2012 to maintain backward compatibility.

From the same forum post, there is a link to the issue on Microsoft Connect, but the issue has been “deferred” by Microsoft’s development team.