TFS 2010 Build: Dealing with the API restriction error

Recently I’ve come across this error a couple of times when running builds that exeucte unit tests using Test containers:

API restriction: The assembly ‘file:///C:Builds<path>myassembly.dll’ has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.

Every time I’ve got this error, the project has been a web application, and the path to the assembly points down to the _PublishedWebsites directory that is created beneath the Binaries folder during a team build.

The error description really says it all (although slightly cryptic), when using test containers, MSTest needs to load all assemblies and see if they contain any unit tests. During this serach, it finds the ‘myassembly.dll’ in two different locations. First it is found directly beneth the Binaries folder, and then it is alos found beneath the _PublishedWebsitesProjectbin folder. The reason is that the default setting for test containers in a TFS 2010 build definition is ***test*.dll:

image

 

This pattern means that MSTest will search recursively for all assemblies beneath the Binaries folder, and during the search it will find the MyAssembly.dll twice.
The solution is simple, set the Test assembly file specification property to *test*.dll instead, this will disable the recursive search:

image

0 thoughts on “TFS 2010 Build: Dealing with the API restriction error”

  1. Originally posted on: http://geekswithblogs.net/jakob/archive/2010/06/08/tfs-2010-build-dealing-with-the-api-restriction-error.aspx#576684

    it took me ages to figure out how to apply this setting, I couldn’t find the dialog in the screenshot above. I eventually changed it by doing the following:

    1: Open Team Explorer
    2: Expand tree until you see builds for your project
    3: Select the build in question
    4: Right Click > Edit Build Definition
    5: Click ‘Process’ on side bar on left
    6: Expand ‘2. Basic’ > Automated tests
    7: Modify value or delete altogether if needs be

Leave a Reply

Your email address will not be published.