AwkwardCoder
AwkwardCoder

Reputation: 25631

"Could not load file or assembly" when building using team city

I'm running into an issue with unit tests on our Team City (8.0.4) build server - the code builds & runs all tests locally via Resharper and nCrunch.

But when running on the server I get the following error, even though the Unity assembly exists in the same directory as the unit test assembly, and is referenced in the unit test assembly.

SetUp method failed. SetUp : System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at XXXX.Unity.UnityContainerAdapter..ctor() at XXXX.GraphExtensionsTests..ctor() in c:\TeamCityV7\Agent-1\work\f02f7e27c0bedfa2\XXXX\Graph.Tests\Extensions\GraphExtensionsTests.cs:line 44

I've confirmed the copy of Microsoft.Practices.Unity is the correct version.

I've also confirmed the assemblies are built using the full version of the framework - not using client profile.

Any ideas why Team City might be failing?

Upvotes: 12

Views: 4610

Answers (3)

Facio Ratio
Facio Ratio

Reputation: 3393

First step is to nuke your local copy of the repository and clone it anew. If you're deploying a branch, switch to that branch before you restore packages and build for the first time. You will get a better clue about the real reason for the problem.

One possibility not listed here is if your test project is a Framework project, but there is a .NET Standard project in the same solution, the test project may not be able to find the package references for the Standard project on a clean clone / restore / build.

Upvotes: 0

user610217
user610217

Reputation:

Another possibility I recently discovered is if you are using a library that you are not explicitly referencing, TeamCity will not collect the library for use and fail when it is implicitly referencing the assembly. I discovered this when trying to figure out why NHibernate.ByteCode.Castle, which was referenced in my test project, was not being loaded and resulting in a FileNotFoundException on TeamCity. Ultimately, I made a "dummy" unit test like so:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NHibernate.ByteCode.Castle;

namespace MyNamespace
{
    [TestClass]
    public class CastleProxyPresenceTest
    {

        [TestMethod]
        [TestCategory("Infrastructure: This test forces TeamCity to load the NHibernate.ByteCode.Castle.dll file.")]
        public void CastleProxyLoads()
        {
            var dummy = new LazyFieldInterceptor();
            Assert.IsNotNull(dummy);
        }
    }
}

...after this, the file loaded properly and my unit tests compiled.

Upvotes: 1

Andy
Andy

Reputation: 8562

Check the pattern you're using to locate your test assemblies. I had a similar problem with another library and it turns out the pattern was finding the test assembly under bin\Release and obj\Release; the obj folder doesn't contain all the assemblies referenced by the project and is really just a scratch folder for the compiler.

Upvotes: 17

Related Questions