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?
For Visual Basic, select Debug in the left pane, select the Enable native code debugging check box, and then close the properties page to save the changes. Select Debug in the left pane, select the Enable native code debugging check box, and then close the properties page to save the changes.
To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.
In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With