Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSTest exception: Unit Test Adapter threw exception: Type is not resolved for member

In my project I write tests using Microsoft's unit testing framework. All of my tests pass when I run them from Visual Studio but when I run the tests from MSBuild all of the tests fail with the following erorr message:

Unit Test Adapter threw exception: Type is not resolved for member SomeType,SomeAssembly Version=assemblyVersion, Culture=neutral, PublicKeyToken=..

The assembly not found is a 3rd party assembly referenced by all of the projects.

The build script is used by TFS so I've aded the following lines:

<RunTest>true</RunTest>

<ItemGroup>
    <MetaDataFile Include="$(BuildProjectFolderPath)myproject.vsmdi">
        <TestList>CI_Tests</TestList>
    </MetaDataFile>
</ItemGroup>

I've found the this post that shows a solution to this issue but unfortunatly I cannot chnage the files on the TFS server.

Help!

like image 706
Dror Helper Avatar asked Jun 21 '10 13:06

Dror Helper


2 Answers

I encountered the same problem in my unit tests. The linked article above indicates that the problem is that VSTS causes copying of some objects in the thread's CallContext.

For what it's worth, in my case the problem was that I had manually placed an object in the thread's CallContext, which caused this exception. I was able to resolve this by clearing the CallContext in my TestCleanup routine. I didn't have to change any files anywhere.

like image 197
telewin Avatar answered Oct 13 '22 04:10

telewin


I had also run into the same issue but where I had StructureMap initialisation being performed within the constructor for a base test class.

I was able to get around the problem by moving the call from the constructor to the [TestInitialize] method. I also ensured that the [TestCleanUp] method disposed of the created StructureMap container. After this MSBuild (2010) would run through the tests without raising this error.

like image 24
Adrian Avatar answered Oct 13 '22 04:10

Adrian