Tuesday, May 22, 2012

TFS Build: The assembly has already loaded from a different location

When trying to run a build on a build server, the unit tests failed with the following error message:

API restriction: The assembly ‘someassembly.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.

This error is caused by a combination of 2 elements. First the solution that I’m trying to build contains a web application. As a consequence the binaries are available at 2 locations; the binaries folder itself but also inside the _PublishedWebsites directory that is created beneath the Binaries folder during a team build.

The second thing is that I’m using the default Test pattern to search for Test assemblies: **\*test*.dll. This pattern indicates that the build engine will search for test assemblies containing the word ‘test’ in the binaries folder AND all subfolders.  As we have 2 places where the same assembly is found(the Binaries folder and the  _PublishedWebsites\Project\bin folder), we are getting into trouble.


So we have to change the default search pattern from **\*test*.dll to *test*.dll. This will disable the recursive search.


1 comment:

Anonymous said...