locked
Difficulties (C0000005) with C++ Native Unit Test (formerly WinUnit) RRS feed

  • Question

  • My Visual Studio configuration seems to be incompatible with Native mode unit testing.  I get a C0000005 error when I do the following:

    1) New -> Project -> C++ -> Test -> Native Unit Test

    2) Right click in TestMethod1 and select Run Tests

    Everything compiles and builds, but the code never makes it to the unit test.

    Here is what I know about the sequence of events (by experimentation with unittest1.cpp and CppUnitTest.h.

    1) If I add a default constructor to my unittest1 class, it will get executed by _new.

    2) The preamble code (generated by the TEST_METHOD macro) runs and properly fills out the data structures which describe the TestMethod1 function (or as far as I can tell it is all correct).

    3) On the first call to _Invoke, the method parameter is NULL (0x00000000).  This causes the C0000005 when trying to call method2.

    I have had a collegue do this same process on his VS 2012 implementation, and his works just fine.  So, I expect that it is related to something in my configuration (which carried over from VS 2010 I believe).  However, I have reverted all of my overrides from property manager pages and can't seem to back off enough to make this work.

    I am wondering if someone could provide a direction for further investigation.

    Thanks.

    Tuesday, September 4, 2012 8:53 PM

Answers

  • I was able to work through this and figured out that the problem is related to using /vmv and /vmg as compile parameters.  The function pointer passed in was not compatible with the /vmv and /vmg generated code.  So, only the first half of the address was being picked up (the first half was null).  When I removed the /vmv and /vmg, the test worked again.

    It is not clear how well this testing will work with a system that uses multiple inheritance (which is why we use /vmv and /vmg in the first place).

    At least I understand the configuration error now.

    Thursday, September 6, 2012 9:51 PM

All replies

  • Hello Prof,

    Thank you for your post.

    Would you mind letting us know more information about this error?

    If the error occurs with an access violation, you can refer to this article: How Can I Debug an Access Violation?

    In addition, you wrote” On the first call to _Invoke, the method parameter is NULL (0x00000000). This causes the C0000005 when trying to call method2.

    If you set a specific method parameter, whether the error will occur or not?

    Also, you can try a simple C++ project and native unit test to check if the error will occur.

    Or you can do the same process on Visual Studio 2010 in another machine to see if it helps.

    If the error still occurs, maybe there is something wrong with your Visual Studio, so you can try the following steps to see if they help:

    a) Try to run devenv /ResetSettings (in command prompt) to eliminate the related potential settings problem.

    b) Try disabling Add-ins (e.g. “Tools” | “Add-in Manager”) or run “devenv.exe /SafeMode”.This can eliminate the possibility that third party Add-ins or packages are causing problems.

    c) Try to reboot the operating system to safe mode. This can help to isolate whether any other applications are interfering with Visual Studio. Note that some features (like IIS) are not available under safe mode. Please check whether this can be applied or not.

      I hope this will be helpful to you.

      Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, September 5, 2012 6:59 AM
  • I think it is important to say that I didn't write any code at all.  I just created the template project and then ran the test.  This is true if I attach a secondary project or not.

    The method __Invoke, is part of the TestClass from CppUnitTest.h in VC/UnitTest/Include.  I don't call it, it is called by some class that is running the tests.  If I use the debugger to modify the method parameter value to have the address of TestMethod1, it will call TestMethod1 fine, but later fails with a buffer overrun.  I concluded that the null method pointer was not coming from trying to call TestMethod1, but some other method for which the metadata is not properly created.

    It is an access violation, but it is obvious why it is an access violation, __Invoke is dereferencing a null pointer.  The debugging occurs in code that I don't have access to and is related to determining why the method parameter to __Invoke is null.

    I am not aware of a way to run Native testing in VS 2010 (without using WinUnit that is).  So, in order to try it there, I would need some pointers on how to make it work.

    I will reboot to SafeMode and try again.  Then post the results here.

    Running in SafeMode, the Test Explorer window crashes with the error below.  This causes all test functionality in VS 2012 to be unavailable.

    An exception was encountered while constructing the content of this frame.  This information is also logged in "C:\Users\JoeUser\AppData\Roaming\Microsoft\VisualStudio\11.0\ActivityLog.xml".

    Exception details:
    System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
       at Microsoft.VisualStudio.Shell.Interop.IVsShell5.LoadPackageWithContext(Guid& packageGuid, Int32 reason, Guid& context)
       at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.GetPackage()
       at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()

    The relevant portion of the ActivityLog.xml file looks like this:

     <entry>
        <record>40</record>
        <time>2012/09/05 14:28:37.640</time>
        <type>Information</type>
        <source>VisualStudio</source>
        <description>Entering function CVsPackageInfo::HrInstantiatePackage</description>
        <guid>{BFC24BF4-B994-4757-BCDC-1D5D2768BF29}</guid>
      </entry>
      <entry>
        <record>41</record>
        <time>2012/09/05 14:28:37.640</time>
        <type>Warning</type>
        <source>VisualStudio</source>
        <description>Appid denied the loading of package</description>
        <guid>{BFC24BF4-B994-4757-BCDC-1D5D2768BF29}</guid>
      </entry>
      <entry>
        <record>42</record>
        <time>2012/09/05 14:28:37.640</time>
        <type>Warning</type>
        <source>VisualStudio</source>
        <description>Package failed to load; error message suppressed by skip flag</description>
        <guid>{BFC24BF4-B994-4757-BCDC-1D5D2768BF29}</guid>
      </entry>
      <entry>
        <record>43</record>
        <time>2012/09/05 14:28:37.644</time>
        <type>Error</type>
        <source>VisualStudio</source>
        <description>Construction of frame content failed.&#x000D;&#x000A;Frame identifier: ST:0:0:{e1b7d1f8-9b3c-49b1-8f4f-bfc63a88835d}&#x000D;&#x000A;Frame caption: Test Explorer&#x000D;&#x000A;Exception details:&#x000D;&#x000A;System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))&#x000D;&#x000A;   at Microsoft.VisualStudio.Shell.Interop.IVsShell5.LoadPackageWithContext(Guid&amp; packageGuid, Int32 reason, Guid&amp; context)&#x000D;&#x000A;   at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.GetPackage()&#x000D;&#x000A;   at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()</description>
      </entry>


    Wednesday, September 5, 2012 2:38 PM
  • I rebooted into safe mode and then ran VS 2012 in safe mode.  It reacted the same way as above.  That is it errored and would not load the testing package.

    I also ran with resetsettings and that also behaved the same as above.  That is the testing package caused a C0000005.

    Wednesday, September 5, 2012 4:35 PM
  • Hello prof,

    The error seems to be related to loading packages failure. You can try running devenv/resetskippkgs to clears all options to skip loading added to VSPackages by users wishing to avoid loading problem VSPackages, then starts Visual Studio.

    About /resetskippkgs  information, please see here:

    http://msdn.microsoft.com/en-us/library/ms241276(v=vs.110).aspx

    If this does not help you, you also can consider repairing or reinstalling your VS.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Amanda Zhu Thursday, September 6, 2012 1:16 AM posted old link
    Thursday, September 6, 2012 1:13 AM
  • I tried running with /resetskippkgs, but that had no effect.  I also ran a full repair on VS2012, which is a brand new installation with no maintenance at all and no other packages installed (other than those that might have auto-migrated from VS2010).

    I don't understand the conclusion that this is related to package management.  There are several errors related to Access Is Denied when running in safe mode, but none of these show up when running normally.

    The problem is related to some object in the Executor.dll file calling __Invoke on the TestClass with a function pointer that is null.  This code is really different from WinUnit and I have no visibility into it.  So, I don't have any way to discover why it is calling invoke, much less why it would send a null pointer.  Can you ask the VS folks that wrote the Native Unit Test modules if they have any idea what circumstances might cause the first call to __Invoke during a test run would have a null pointer when running a blank testing template project?

    		virtual void __Invoke(__voidFunc method)
    		{
    			typedef void (ThisClass::*voidFunc2)();
    			voidFunc2 method2 = static_cast<voidFunc2>(method);
    
    			CrtHandlersSetter setter;
    			(static_cast<ThisClass *>(this)->*method2)();
    		}
    

    Fragment from VC/UnitTest/Include/CppUnitTest.h.  "method" is null when this function is called for the first time.

    Thanks for any clues you can provide.

    Thursday, September 6, 2012 4:57 PM
  • I was able to work through this and figured out that the problem is related to using /vmv and /vmg as compile parameters.  The function pointer passed in was not compatible with the /vmv and /vmg generated code.  So, only the first half of the address was being picked up (the first half was null).  When I removed the /vmv and /vmg, the test worked again.

    It is not clear how well this testing will work with a system that uses multiple inheritance (which is why we use /vmv and /vmg in the first place).

    At least I understand the configuration error now.

    Thursday, September 6, 2012 9:51 PM
  • This article may help you. this is a simple step by step guide for native C++ unit test.

    http://codeketchup.blogspot.sg/2012/12/unit-test-for-unmanaged-c-in-visual.html

    Friday, December 7, 2012 8:44 AM