After a bit of tinkering, I finally managed to find the sweet spot for getting xUnit 1.5 to run (without errors) with projects targeted at the new .NET 4.0 Framework.
After initial solution conversion, if you run your tests with xunit.console.x86.exe (or the 64-bit version, I’m assuming), you’ll face the following helpful error:
System.BadImageFormatException: Could not load file or assembly 'Assembly.Test.dll' or one of its dependencies. This assmbly is built by a runtime newer than the currently loaded runtime and cannot be loaded. File name: 'J:\projects\Framework\build\Assembly.Test.dll' at System.Reflection.AssemblyName.nGetFileInformation(String s) at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) at Xunit.Sdk.Executor..ctor(String assemblyFilename) at Xunit.ExecutorWrapper.RethrowWithNoStackTraceLoss(Exception ex) at Xunit.ExecutorWrapper.CreateObject(String typeName, Object args) at Xunit.ExecutorWrapper..ctor(String assemblyFilename, String configFilename, Boolean shadowCopy) at Xunit.ConsoleClient.Program.Main(String args)
What? BadImageFormatException? But the bitness didn’t change!
Here’s what the new configuration files need to include:
<startup uselegacyv2runtimeactivationpolicy="true"> <supportedruntime version="v4.0.30319" /> </startup>
The useLegacyV2RuntimeActivationPolicy attribute ensures that the latest supported runtimes are loaded. For my projects, this seems to keep Oracle.DataAccess.dll and System.Data.Sqlite.dll (both x86 libraries) happy.
The supportedRuntime element denotes the current version of .NET 4.0 (30319 is the RTM build).
After that, everything runs like a champ!
xUnit.net console test runner (32-bit .NET 4.0.30319.1) Copyright (C) 2007-9 Microsoft Corporation. xunit.dll: Version 18.104.22.168 Test assembly: Assembly.Test.dll Total tests: 397, Failures: 0, Skipped: 0, Time: 7.508 seconds