views:

165

answers:

1

I am developing an assembly which has to be installed in the GAC, and as part of a post-build step I ensure that the GAC gets updated after each build. If I create a (Visual Studio) unit test (in a seperate tests assembly) to call a new method on a class under test, then implement the method on the class under test (TDD style), then run the test (CTRL R, T) the assembly under test and the unit test project get built (and the assembly is updated in the GAC).

The test fails (throws a System.MissingMethodException for the new method). If I now debug the test the test passes and thereafter I can run the test and it will pass.

As part of my investigation I added an endless loop to the test and then ran it. I used Process Explorer to find the path of the dll that gets loaded during the test. I find that there is a handle to an assembly in C:\WINDOWS\assembly\temp\4XY349E7C5. Using the trick I found here to look in that directory I find an older version of my dll than is in the GAC, and if I use Reflector to examine the dll I find it does not contain the new method I added which explains the MissingMethodException.

So why does VSTestHost.exe load the dll in the temp directory, and is there some way for me to ensure the correct dll is used?

A: 

Reading this article pointed me towards the reason for the problem - VSTestHost.exe is keeping the old version of the assembly loaded (i.e. the version refered to in the gac\temp folder, which fusion will unload when VSTestHost exits).

The solution to the problem was to change the setting in Tools/Options/Test Tools/Test Execution - uncheck "Keep test execution engine running between tests". Now VSTestHost starts a new instance for each test run and loads the correct version of my dll from the GAC.

pete757