locked
Using mixed-mode debugging on a managed unit test in Visual Studio 2013 RRS feed

  • Question

  • 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?

    Tuesday, January 13, 2015 11:39 PM

Answers

All replies

  • Hi Chris Becker,

    If possible, could you please share us a sample to reproduce and research your issue on our side?

    In order to make test be debugged, please make sure that the PDB files related to the C++ DLLs are copied to your test output directory and they are generated with the latest build.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 14, 2015 8:24 AM
  • Hi Chris Becker,

    If you have any information, please feel free to come back.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 19, 2015 8:51 AM
  • Hi Chris,

    Firstly, we would know what the requirements are for mix mode debugging:

    The following procedures describe how to debug both managed and native code, also known as mixed-mode debugging. There are two scenarios for doing so, depending on whether the DLL or the application is written in native code:

    • The calling application that calls your DLL is written in native code. In this case your DLL is managed, and both managed and native debuggers must be enabled to debug both. You can check this in the <Project> Property Pages dialog box. How you do this depends on whether you start debugging from the DLL project or the calling application project.

    • The calling application that calls your DLL is written in managed code and your DLL is written in native code.

    https://msdn.microsoft.com/en-us/library/kbaht4dh.aspx

    As my understanding, it is related to the VC++ app.

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

    In the C# project properties pages, under the debug tab

    Check "Enable native code debugging".

    http://blogs.msdn.com/b/stevejs/archive/2004/05/05/126497.aspx

    http://stackoverflow.com/questions/6738006/how-do-i-debug-a-native-code-project-from-inside-a-managed-code-project-c-c

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, January 27, 2015 8:06 AM