Wednesday, January 30, 2013

Debugging Problem with Visual Studio 2012 Unit Test

Today I found a very annoying problem while debugging my unit test with Visual Studio 2012. In a usual case scenario, when you are debugging your assembly code, at any breakpoint you can hit F10 or F11 to step over or step into the code line by line. However, today I find it behave differently, when I step over my code, the execution is skip jumping a few lines or more.

I would like to share the steps how I troubleshoot this problem and found the root cause and resolution.

First, check all your projects are not running in "Optimize Code" by opening up project properties and look for Build section then locate the "Optimize Code" checkbox is not checked.



Then, run your projects in debug mode, open up the Module window from the Debug menu, and then check all your assemblies are loaded and identify all the symbol paths are correct.


The loaded symbol paths look fishy. When you go to the project bin folder, you would notice that there are extra pdb files in the folder. For example:

<Assembly Name>.dll
<Assembly Name>.pdb
<Assembly Name>.instr.pdb

And then, in your Module window, it shows that the loaded symbols are actually <Assembly Name>.instr.pdb.

Well, when we enable Code Coverage in unit test, the instrumented assembly will be generated into another set of *.pdb files which are named as <Assembly Name>.instr.pdb. I never notice the *.instr.pdb would actually get loaded instead.

After disabling the Code Coverage, Test Impact, Intelli Trace, everything from my unit test setting, then do a solution cleaning and rebuild, no more *.instr.pdb file is generated. While debugging the code, only normal *.pdb files get loaded and no more code jumping around after hitting F10.

However, I am a little bit curious what is the actual root cause, so I go and enable back the Code Coverage. Surprisingly, *.instr.pdb files are not generated. So, I go and enable Test Impact, now I see *.instr.pdb files are generated, and I replicated the same problem occur earlier again.

So, is it a bug in Visual Studio 2012? :P



6 comments:

  1. This bug has eaten so many hours of my days, very annoying bug. But thnxs now I know the cause!

    ReplyDelete
  2. Kudos to you Mr Lee. That fixed my issue too! I agree with you and looks like a bug in VS 2012.

    ReplyDelete
  3. Took me term to entryway all the explanation, but I in all actuality partook in the article. It ended up being Very respecting me not entirely set in stone to all the analysts here! Its generally accessible by means of now you can't unmarried-handedly be learned, however with engaged! Megasync Pro Crack

    ReplyDelete

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API. Transactional SMS usually come with One Tim...