locked
System.MissingMethodException when runing unit test

    Question

  • Hi,

     

    I'm trying to run a unit test for my project and for the life of my I can't figure out why I keep getting the error "System.MissingMethodException".  If I choose to Debug the unit test it works great, but when I try to Run it, I get that MissingMethodException error.

     

    I've deleted the output directories, rebuilt a thousand times, removed and re-added the references to project that the unit test references, jumped up down, brought other developers over, etc...  Intellisense finds the method when I'm writing the test so why the problem when I run it?

     

    Why does Debugging the unit test work, but not Running the unit test?  This is soooo frustrating!  This falls under the category: TIME SUCKING PROBLEM WHILE UNDER A DEADLINE.  Arg.  Who do I send the bill to?

     

    Thanks.

     

     

    Friday, May 18, 2007 12:16 AM

Answers

  • I am sorry about the problem you are experiencing. This prolem will be better addressed in our testing forum:

    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=19&SiteID=1

    In general, this problem is usually caused by mismatch between the live code and executed test binary. In VS IDE, we are trying to detect unit tests presence in the live pre-compiled code, based on Visual Studio Code Model. It is possible that some of your unit tests do not have the required unit tests signature and we have failed to detect that in VS IDE and we are trying to execute a non-valid or missing unit test. Sometimes just refreshing the test view or rebuilding your solution helps.

     

    I would recommend that you post a real code example in the testing forum above, so that we could track the problem or provide a more specific workaround.

     

    Regards,

    Boris

    Wednesday, May 23, 2007 6:25 PM

All replies

  • My 2c:

     I was having the same problem: unit tests were working fine till I changed return type, afterwards getting same exception as you, tried pretty much the same things you did.

    What seems to have fixed it for me is changing active configuration (we have 3: Debug, Release, Automated). I had Debug on, switched to Release, rebuild; switch to Automated, rebuild. Run Unit test under Automated and Release, it worked. Then switched back to Debug, rebuild --> unit tests are passing again.

    I don't know what causes this problem, this just seems to have fixed my problem. Hopefully it does the same for you.

    Good luck.

    • Proposed as answer by JS_MSDN Thursday, March 17, 2011 8:20 AM
    Monday, May 21, 2007 11:38 PM
  • I am sorry about the problem you are experiencing. This prolem will be better addressed in our testing forum:

    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=19&SiteID=1

    In general, this problem is usually caused by mismatch between the live code and executed test binary. In VS IDE, we are trying to detect unit tests presence in the live pre-compiled code, based on Visual Studio Code Model. It is possible that some of your unit tests do not have the required unit tests signature and we have failed to detect that in VS IDE and we are trying to execute a non-valid or missing unit test. Sometimes just refreshing the test view or rebuilding your solution helps.

     

    I would recommend that you post a real code example in the testing forum above, so that we could track the problem or provide a more specific workaround.

     

    Regards,

    Boris

    Wednesday, May 23, 2007 6:25 PM
  • Hello guys,

    Same problem, another solution: Be carefull that your assembly not been installed in GAC. In my case, I installed my assembly in GAC and after I changed the code. When I performed unit testing, I had the follows error: System.MissingMethodException. After some hours, finally I had a diagnostic: uninstall the assembly of GAC.

    I hope that it help you!

    Regards,

    Evandro Venancio
    Tuesday, August 05, 2008 8:18 PM
  • I had the same problem. In my case, turning of Code Coverage made it go away. The problem did not return when I turned Code Coverage back on.
    • Proposed as answer by Jaybirdbsu Friday, April 22, 2011 12:54 AM
    Friday, February 18, 2011 1:25 PM
  • This worked like a charm for me!

     

    Thanks

     

    Jay

    Friday, April 22, 2011 12:54 AM
  • Hello guys,

    Same problem, another solution: Be carefull that your assembly not been installed in GAC. In my case, I installed my assembly in GAC and after I changed the code. When I performed unit testing, I had the follows error: System.MissingMethodException. After some hours, finally I had a diagnostic: uninstall the assembly of GAC.

    I hope that it help you!

    Regards,

    Evandro Venancio
    Damn, that was the issue with me. Did a lot of googling to get to your post Evandro. Thanks
    Fahad
    Tuesday, September 13, 2011 5:31 PM
  • It seems that there are several causes of this problem. In my case, I have multiple branches of code for my common library (DLL) projects. I use the branches to help separate changes for parallel projects, with integration as the projects are ready to move toward install. I had changed branches at some point, and then changed back. I have Code Coverage turned on. As I look at the list of "artifacts to instrument" while editing the Code Coverage settings in the test run config, I notice that it lists two sets of DLLs: one from the temporary branch and one from regular branch.

    I'm currently building my updates in the regular branch, but code coverage is looking at the temporary branch still. Thus although I'm able to compile just fine, the code coverage tool does not see my new methods. Solution is to manually select the correct DLLs to instrument.


    After updating the test run config, I had to close Visual Studio and re-open. Before doing so, even the non-code coverage test run config continued to get errors.
    • Edited by sfuqua Monday, October 03, 2011 9:54 PM
    Monday, October 03, 2011 9:29 PM
  • Great!
    Tuesday, November 08, 2011 11:54 PM
  • This worked for me as well!
    Thursday, February 23, 2012 5:24 PM
  • simply deleting the bin and obj folder of the project that had the 'missing exception' did the trick for me. it recompiled and run successful.
    Friday, October 12, 2012 6:20 PM