Using mixed-mode debugging on a managed unit test in Visual Studio 2013
Asked Answered
S

1

19

I have a C# unit test in the Visual Studio 2013 test framework which exercises CLI and native code. I would like to investigate the native portion of the code while executing the C# unit test. However running Test -> Debug -> All Tests runs the managed debugger, so break points in native code are not hit and I cannot trace from C# -> C++/CLI code like I can when running the program under a mixed mode debugger.

For example, this code in my unit test:

[TestMethod]
public void TestRoundTripEvaluate()
{
     var obj = new MyCLIObject();
     var roundtripped = RoundtripXml( obj );

     // I would like to trace into here to see why Equals returns false.
     // But the definition for MyCLIObject is in a CPP file and cannot be navigated 
     // to running the unit test because Visual Studio starts the debugger as "managed only"
     // when using Test -> Debug -> All Tests
     Assert.IsTrue( obj.Equals( roundtripped ) ); 
}

Looking at the project settings for the unit test project, everything under Debug is disabled, so I can't check Enable Native Code Debugging, which allows this behavior for a normal program.

How can I enable mixed-mode debugging or native only debugging when running a VS C# unit test?

Sentimentality answered 25/12, 2014 at 20:21 Comment(1)
I'm using vs2013 update 4 and the checkbox "Enable native code debugging" is available. Which version of VS are you using?Manlike
L
19
  1. Go to the properties page for your unit test project (right-click on project in Solution Explorer, then click "Properties")
  2. Go to the "Debug" tab (4th from the top in the list on the left-hand side)
  3. Enabled the checkbox "Enable native code debugging"
  4. Debug your unit test - you can set breakpoints in either native or managed code, and you can step into either kind of code.

I just had the same problem as you and was able to make it work using these steps. Before enabling this checkbox, it did not work. For the record, I'm using VS2013 update 4.

enter image description here

Liris answered 25/3, 2015 at 0:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.