Always getting "Could not locate the assembly nunit.framework..."!
Hi,
I'm trying to get TeamCity to run NUnit tests as set up in an NAnt script as follows:
<nunit2>
<formatter type="Xml"
usefile="true"
extension=".xml"
outputdir="${BuildArea.ReportsDir}" />
<test assemblyname="${BuildArea.OutputDir}\Common.Tests.dll"
appconfig="src\Common.Tests\Tests.config" />
</nunit2>
Manually running the build script from the command line on the buildserver/agent machine runs the tests just fine so i know that there's no problem with the build script itself. However when a build runs from within TeamCity i always get the error:
"Could not locate the assembly nunit.Framework"
I've come across a related post (http://devnet.jetbrains.net/message/5211436#5211436) which recommends placing nunit.framework at the same location as the dll containings the tests but i was doing this already and i'm still getting the same error. Installing to the GAC is not an option.
Anyone has any idea how to fix this? I've spent hours trying to figure out what might be the problem but i can't see what i might be doing wrong.
Thanks
Exact error and stack trace follows:
[23:48:02]:
NUnit Error: System.IO.FileNotFoundException: Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified.
File name: 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77'
Server stack trace:
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at NUnit.Core.TestFramework.FromAssembly(Assembly assembly)
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
at NUnit.Core.Builders.TestAssemblyBuilder.Build()
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String testName)
at NUnit.Core.TestSuiteBuilder.Build(String assemblyName, String testName)
at NUnit.Core.SimpleTestRunner.Load(String assemblyName, String testName)
at NUnit.Core.SimpleTestRunner.Load(String assemblyName)
at NUnit.Core.ProxyTestRunner.Load(String assemblyName)
at NUnit.Core.ProxyTestRunner.Load(String assemblyName)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Core.TestRunner.Load(String assemblyName)
at JetBrains.TeamCity.NUnitLauncher.NUnitRunner.LoadTest(String testAssembly, String testName, TestRunner runner) in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\NUnit-2.2\NUnitRunner.cs:line 33
at JetBrains.TeamCity.NUnitLauncher.AssemblyTest.LoadTestDomain() in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\AssemblyTest.cs:line 71
at JetBrains.TeamCity.NUnitLauncher.LoadTestDomainAction.Action(AssemblyTest test) in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\LoadTestDomainAction.cs:line 14
at JetBrains.TeamCity.NUnitLauncher.TryOneAssemblyTest.Action() in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\TryOneAssemblyTest.cs:line 18
at JetBrains.TeamCity.NUnitLauncher.TryOneAssembly.Do() in c:\Agent\work\e34bdcb45e12f223\src\NUnitLauncher\src\TryOneAssembly.cs:line 31
Please sign in to leave a comment.
Can anyone from JetBrains advise on this? Thanks
Please check NUnit.Framework 2.4.8.0 is available near test assemblies or in GAC on the build agent machine. What NUnit version is used in the project, dependent assemblies? What version of NUnit is selected in TeamCity?
NOTE: I started writing the post with the tests still not running but as i run everything yet again in order to provide some info for the post i eventually found that due to the assembly binding redirect, teamcity needs NUnit 2.2.8 (which is the version NAnt is built against) to be either at the same location as the test dll or in the GAC. While this gets things working, i'm still not sure why this is required for TeamCity in the first place since on the development machine NUnit is neither at the same location as the test dll nor in the GAC yet NAnt seems to be able to find the nunit.framework.dll (2.2.8) within it's own lib folder. Anyhow... here's a run down from which others might benefit:
The solution is a VS2008 solution. Within the test project i am referencing NUnit 2.4.8. Along with the test project i have a Tests.config file for assembly binding since NAnt is built against a different NUnit version. The tests.config file is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework"
publicKeyToken="96d09a1eb7f44a77"
culture="Neutral" />
<bindingRedirect oldVersion="2.4.8.0" newVersion="2.2.8.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The Nunit2 task of the NAnt script is as follows:
<nunit2>
<formatter type="Xml"
usefile="true"
extension=".xml"
outputdir="${BuildArea.ReportsDir}" />
<test assemblyname="${BuildArea.OutputDir}\Common.Tests.dll"
appconfig="src\Common.Tests\Tests.config" />
</nunit2>
Running on a development machine, WITHOUT nunit.framework of any version in the GAC or in the same location as the dll containing the tests works fine.
Now...on the teamcity buildserver i have the following scenario (all of which fail)
1. NO build parameters set in "Properties and environment variables":
Build script fails with the following error:
NUnit Error: System.IO.FileNotFoundException: Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified.
File name: 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77'
2. The following build parameters set in "Properties and environment variables":
a. teamcity.dotnet.nant.nunit2.platform set to value x86
b. teamcity.dotnet.nant.nunit2.platformVersion set to value v2.0
Build script fails with the same error as above
3. The following build parameters set in "Properties and environment variables":
a. teamcity.dotnet.nant.nunit2.platform set to value x86
b. teamcity.dotnet.nant.nunit2.platformVersion set to value v2.0
c. teamcity.dotnet.nant.nunit2.version set to value NUnit-2.4.8
Build script fails with the following error indicating that it is picking up the instruction for the assembly binding:
NUnit Error: System.IO.FileLoadException: Could not load file or assembly 'nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' ---> System.IO.FileLoadException: Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77'
4. Installing nunit.framework.dll (2.4.8) to GAC:
Same errors as above.
5. Installing nunit.framework.dll (2.2.8) to GAC:
Finally... the tests run!
If anyone could suggest why when run from within Teamcity NAnt cannot find the dll it would be nice.
It's strange (to me at least) how this hasn't been mentioned before since all versions of NAnt, including the latest stable 0.90 release, use NUnit 2.2.8. Whatever the case though, at least the tests will now run.
TeamCity have it's own build runner. As I see from the post, our NUnit runner failed to support binding redirect for NUnit.Framework assebmly. TeamCity bundle some versions of NUnit framewrork. Why had it failed to find NUnit 2.2.8? We decided to switch to NUnit 2.2.10 in the build runner, thus there is no NUnit.Framework.dll 2.2.8 found in the build agent. Will it work if you specify binding redurect to NUnit.Framework 2.2.10 assembly? On the other hand, NUnit 2.4.x and NUni 2.5.x have too much new features and bug fixes, so I would recommend using latest NUnit test runner any way.
NUnit test runner will work right if you will have NUnit.Framework.dll assebmly places near your test classes. There is not necessary to have NUnit.Framework.dll of the same version as NUnit test runner is and it is not necessary to have any assembly binding redirects too.