Run All Tests results in "Specified cast is not valid" RRS feed

  • Question

  • Hello,

    I'm trying to run unit tests in Visual Studio 2010.  I've just installed a fresh copy of 2010.  When I add a test project to my solution and add my tests, then click "Run All Tests," I get a popup with a red error icon and the message, "Specified cast is not valid."

    Additionally, I cannot run these tests from the Test List Editor: I get a popup with the red error icon and the message, "No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

    These tests run correctly when I run one test class at a time.  

    Tuesday, February 1, 2011 6:37 AM

All replies

  • Hi,

    Are you sure that all of your tests run individually and its not an issue with a specific test. If yes, can you try resetting your settings by referring http://msdn.microsoft.com/en-us/library/ms247075(v=vs.80).aspx



    Tuesday, February 1, 2011 6:38 PM
  • Yeah, I can run each test individually, and all the tests in the solution pass. Very, very rarely I can run all the tests at one time, but the next time I try, I'll get the same errors I mentioned in my first forum posting. I'll then have to run tests either individually, or one class at a time. I tried resetting Visual Studio's settings, but get the same results.
    Monday, February 7, 2011 12:11 AM
  • Hi,

    Not really sure what's causing the issue. Can you try onr more, try running the tests from VS command line:

    mstest /testcontainer:"test assembly"

    Please see if you get the same issue.



    Monday, February 7, 2011 2:42 AM
  • When I run it from the command line like that, it runs fine every time.
    Monday, February 7, 2011 3:35 AM
  • Hmm, can you go the solution items and delete the vsmdi file. Then click on Test->Create New Test List and try running the tests again.



    Monday, February 7, 2011 3:47 AM
  • Nope, same results.  I tried doing that several times, but didn't have an effect.
    Monday, February 7, 2011 4:00 AM
  • One last thing :)

    Can you pass the /testsettings parameter to mstest and see if you get the same issue.



    Monday, February 7, 2011 4:56 AM
  • Absolutely, anything if it helps solve the problem.  

    I ran the previous command you'd given me, and this time I also passed in the testsettings parameter, using both my Local.testsettings file and TraceAndTestImpact.testsettings file.  Both options were successful, and all tests ran correctly.

    Monday, February 7, 2011 5:13 AM
  • Sorry, I mentioned testsettings instead of testlist. Can you please try with passing the following parameter to mstest:

    /testlist:"All Loaded Tests"



    Monday, February 7, 2011 5:37 AM
  • No problem.

    I ran mstest using my solution's vsmdi as the /testmetadata parameter, then specified "All Loaded Tests" as the /testlist parameter. I got this:

    The test list path All Loaded Tests cannot be found.

    An error occurred while executing the /testlist switch.

    I tried creating a named test list in the vsmdi and added all the tests to that list.  When I ran mstest using that test list for the /testlist parameter, everything ran correctly.


    Monday, February 7, 2011 5:46 AM
  • In case anyone runs across this issue, here is what I did to fix it:

     - Go to the properties of the test project

     - Open the "Assembly Information" pop up

     - Click "Make Assembly Com Visible" to change its state (eg. If ticked, clear it, if not ticked, tick it).

     - Close the pop up, save the project

     - If you have cleared the "Make Assembly Com Visible" check box, reopen the dialogue and set it to true, then close and save

    The tests should now run (well, they did for me!).  I encountered this issue using Visual Studio 2010 Professional with SP1, while developing a XNA application.  I have to do this after every time I rebuild the solution.

    Thursday, May 1, 2014 3:36 PM