4
votes

I'm getting this error trying to execute my tests using nunit2 task

Failure executing test(s). If you assembly is not built using NUnit version 2.6.0.12051, then ensure you have redirected assembly bindings

The nunit version for my test project is 2.6.2.12296.

I tested several redirect bindings on my test project config file but nothing did the trick. I know I could use EXEC to run nunit.exe directly instead of using nunit2 task but I'd like to make this work.

UPDATE

This is my current app.config for the testing project

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="nunit.framework" publicKeyToken="96d0234a77" culture="Neutral" />
          <bindingRedirect oldVersion="0.0.0.0-2.6.0.12051" newVersion="2.6.2.12296" />
        </dependentAssembly>
    </assemblyBinding>

  </runtime>
</configuration>

UPDATE 2

This is the relevant part of the build file

<nunit2>
  <test 
    assemblyname="D:\[the full path]\UnitTests.dll" 
    appconfig="D:\customTest.config"/>
  <formatter type="Plain"/>
</nunit2>
3
does this error happen also when you start debug your project?giammin
@giammin: no, this error only happen when running nantStackOverflower
could you post your nant .build filegiammin

3 Answers

3
votes

When you use NAnt NUnit2 tasks if the version of your test framework does not match with the version NAnt was built with you have to tell NAnt NUnit2 tasks to use binding redirect.

The problem is that NUnit test runner creates a new AppDomain for each test so you can't do a binding redirect with the app.config of the testing project.

You have to create a custom config file with the binding redirect:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="nunit.framework" publicKeyToken="96d0234a77" culture="Neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.6.2.12051" newVersion="2.6.2.12296" />
    </dependentAssembly>
  </assemblyBinding>
</runtime> 

And tell NUnit2 NAnt task to use it:

<nunit2>
    <test assemblyname="ProjectName.Tests.dll" appconfig="customTest.config" />
     ...
</nunit2>

--------------Last thought------------------------------

your config is:

<bindingRedirect oldVersion="0.0.0.0-2.6.0.12051" newVersion="2.6.2.12296" />

try with

<bindingRedirect oldVersion="0.0.0.0-2.6.2.12296" newVersion="2.6.2.12296" />

and double check if all external references of your test project are copy local=true in visualstudio properties window

2
votes

Add <bindingRedirect> to your .config as described in NUnit documenation:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="nunit.framework" publicKeyToken="96d0234a77" culture="Neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.6.2.12051" newVersion="2.6.2.12296" />
    </dependentAssembly>
  </assemblyBinding>
</runtime> 

Or use Nant <exec> like:

 <exec program="${LibraryPath}\NUnit\2.6.2\nunit-console.exe">
   <arg value="${SourcePath}\ProjectName.Tests\bin\Release\ProjectName.Tests.dll" />
 </exec>
1
votes

I had the same problem.

My solution was to change the platform from x86 to Any CPU. It seems that nunit has problems with different platforms.

Greets