Search code examples
c#.netunit-testingwindbgintellitrace

WinDbg'ing Unit Tests C#


What's my question/problem? I'm trying to use WinDBG to attach to a few of my unit tests, which are in a Class Library (Unit Test Project), but I can't get WinDbg to break on managed exceptions.

Why am I doing this? Currently I have tests that utilize shims and are bumping into this issue: UnitTestIsolationException: Throws Exception while running Shims test in Release/Debug mode

However, this is ONLY happening when these tests are run in tandem (same playlist in test explorer) with some other tests that aren't using shims. When run individually, the tests pass fine.

So, I figured I'd fire up WinDbg (with my very limited knowledge of it), attach to the test runner, and break on the exceptions there.

What I've Tried: Since this is a DLL it's obviously being loaded up by some executable to run the code within the tests (test runner). While I was originally just running these tests in Visual Studio, I had trouble determining which process to attach WinDbg too, so instead I started using vstest.console.exe to start running the tests, then attach to that.

I'm able to attach fine, and WinDbg halts the execution of the test runner (yay!).

Now, I want to break as soon as a CLR exception is thrown (meaning my UnitTestIsolationException). After googling, I found the windbg command to do so: sxe clr

Then I type g, and the program starts running through my tests again.

Behavior I'm seeing: WinDbg never breaks on the UnitTestIsolationException - all the tests run to completion, the test results are printed to the console, then the program terminates:

Passed   [SomePassingTestName]
Passed   [SomePassingTestName]
Failed   [TheFailedTestMethodName]
Error Message:
   Test method [TheFaileTestMethodName] threw exception:
   Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationExceptio
n: Unexpected error returned by SetDetourProvider in profiler library 'C:\Progra
m Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsof
t\IntelliTrace\14.0.0\Microsoft.IntelliTrace.Profiler.14.0.0.dll'.

Solution

  • I prefer psscor but try

    !StopOnException -derived -create System.Exception