Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have unit tests that pass in NUnit GUI and Resharper, but fail when Team City runs them

Tags:

teamcity

nunit

I have a TeamCity server set up to build multiple solutions and then run the unit tests in them using the NUnit Test Runner.

This has been working perfectly for several months; however, with our latest build I am encountering the following error:

SetUp method failed. SetUp : System.IO.FileLoadException : Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

It only happens for a single TestFixture that contains 9 tests out of hundreds in the entire system. The tests all pass when run using ReSharper or the NUnit GUI.

The Nuget package is correctly referenced in both the project being tested and the test project itself. There are no runtime assembly binding redirects necessary as only one version of Log4Net has ever been installed.

Has anybody else had a similar issue that they have solved or any ideas as to what the issue might possibly be? Why would it work locally and not on the server, especially given the same tests passed previously.

The versions of NUnit on both my local machine and my TeamCity server are the same.

like image 206
tker Avatar asked Sep 29 '22 08:09

tker


1 Answers

I'll just answer my own question in case anybody else encounters this.

The issue seems to be that Log4Net's assembly manifest has been packaged incorrectly, or at least differently from how one might expect.

This arises from the DLL version being 1.2.13, but the NuGet package version being 2.0.3.

What we did was add an assembly binding like the following, which fixed the issue:

<dependentAssembly>
    <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="2.0.3" />
</dependentAssembly>

I have absolutely no idea why this only failed for one project out of ~60 being built or why it worked within my dev environment VS/ReSharper Nunit test runner, but failed for TeamCity!

like image 146
tker Avatar answered Oct 22 '22 19:10

tker