MissingMethodException when running unit test on Visual Studio

This is one of those errors, that I had to scratch my head for a while to work it out. So thought I'd share here just in case if anyone else is having the same issue. Keep in mind mileage may vary since red bumps doesn't always mean an insect bite (it could also mean you've got a skin cancer!).

The Problem

Running Unit test from Visual Studio Test Runner or Resharper Test Runner gives me:

Initialization method Core.Tests.UriWithQueryStringsSpecifications+when_url_contains_existing_query.
Context threw exception. 
System.MissingMethodException: System.MissingMethodException: Method not found

It basically can't find the new piece of method that I just created.

I thought Visual Studio was caching the assembly under test, so I tried restarting Visual Studio and even deleting the shadow copy (C:\Users\{name}\AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies), but doesn't seem to fix it.

I was even tempted to restart my computer ’¦

What's really happening

Since I'm working with Sharepoint 2010, I didn't really realize that the assembly under test is already deployed to the GAC in my previous deployment.

It's interesting to note that Visual Studio then doesn't even try compiling it into the bin folder of the test since it found it in the GAC!

The Fix

The fix is simple and quite obvious once I figured out the problem, re-deploy the assembly under test to the GAC again. This is quite annoying since an extra step one has to do especially if you're doing test driven development : Sharepoint deployment takes a few seconds if not minutes!

So what I had to do to were the following:

Uninstall the assembly from the GAC, by going to c:\windows\assembly on the explorer, right click and uninstall.

image

Re-deploy the assembly into GAC, or if you're working with SharePoint then just re-deploy the package.

Alternative Fix

Alternatively I guess I can point the Test Project Reference to a hardcoded path of the dependent Project. I *think*  (I haven't tried it), it should ignore the copy in the GAC and use the dll in the specified path.

image

This is probably going to speed up build and test time, just remember to update the path should you rename the assembly.

  1. Venkatx5 says:

    Got the same issue and found solution myself. :) Then searched to know proper reason. Thanks Dude..