2

After following several blogs detailing how to get xUnit working with Team Services Build vNext:

None of which worked for me. From examining the build logs I get the following warnings for each of my test assemblies.

--------------------
 Warning: [xUnit.net 00:00:00.1644156] Exception discovering tests from CHO.SAM.Business.Test: System.BadImageFormatException: 
 Could not load file or assembly 'c:\_Work\473cef3c\CHO\CHO.ALL\Tests\CHO.SAM.Business.Test\CHO.SAM.Business.Test\bin\Debug\xunit.execution.desktop.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
--------------------

Has anyone seen this before? and if so did you figure out a solution?

My thoughts are; my test projects are compiled using .NET Framework 4.6, I was wondering if this could be causing the problem? If so I would have to move over to nUnit or something as I don't feel it's right to change the compilation just to use a single test framework.

Community
  • 1
  • 1
Choco
  • 1,189
  • 1
  • 14
  • 29
  • By the way it works fine in Visual Studio, builds, runs, and recognizes tests.. all good. – Choco Sep 25 '15 at 04:20
  • The symptoms look similar to those described [here](http://stackoverflow.com/questions/32659106/tfs-2013-building-net-4-6-c-sharp-6-0) and [here](http://stackoverflow.com/questions/28287737/c-sharp-6-0-tfs-builds). See if any suggestion from there helps. – Yan Sklyarenko Oct 02 '15 at 08:23
  • I followed through on your links, but my problem seemed to be slightly different. thx... :-) – Choco Oct 05 '15 at 02:03
  • Did you find a solution to this? I'm having the same issue, but with a TFS 2015 XAML build using 4.6.1 – Rob H Jan 26 '16 at 15:42
  • I added a UI test, it just sits there with nothing inside it! But it causes it to work. Was using build vNext. so don't know with XAML.. – Choco Jan 27 '16 at 03:06

5 Answers5

2
  • Add "/Framework:Framework45" to "Advanced/Other console options" (to run under .NET 4.5)
    or
  • Add "/Framework:Framework40" to "Advanced/Other console options" (to run under .NET 4.0)
    or
  • Change "Advanced/VSTest version" to "Visual Studio 2013" (to run under .NET 3.5)
MEMark
  • 1,493
  • 2
  • 22
  • 32
1

This error is normally caused by a x64 compiled assembly running on x86 test runner or vice versa. Check the solution build configuration that is being run.

Scott Mackay
  • 1,194
  • 10
  • 34
1

I had this same issue. Adding a UI test did not fix it for me. I found two alternatives that work:

  1. use .net 4.5

    OR

  2. Set the advanced options of the VSTest task to use 2013 instead of 2015.

Hopefully this will be fixed soon.

Community
  • 1
  • 1
Daniel Auger
  • 12,535
  • 5
  • 52
  • 73
  • didn't have the option to choose 4.5... I suspect it's caused because the xunit libraries are 4.5... – Choco Jan 27 '16 at 03:04
0

In the end, I added a Visual Studio Coded UI test project and removed all it's contents (a class), it's empty!

I'm assuming it's added a reference or something that the build server felt it needed.

I am now getting my unit tests discovered, running and with code coverage.

Wierd!

It works, but I don't know why...

Choco
  • 1,189
  • 1
  • 14
  • 29
0

I ran into this issue when using a .Net Core class library to run my xUnit tests against a .Net Core Web Project (.Net Framework). What solved the issue for me was to change the default processor for running test to X64 in VS2015 via:

Menu Bar -> Test -> Test Settings -> Default Processor Architecture -> X64

This solution was posted by @RehanSaeed here https://github.com/dotnet/cli/issues/3103

RonC
  • 31,330
  • 19
  • 94
  • 139