dotnet test with xUnit and full .NET framework causes System.BadImageFormatException
See original GitHub issueSteps to reproduce
Create a web application that targets full .NET framework, e.g. with:
"frameworks": { "net461": { } },
Create a class library with xUnit, testhost and web application as dependencies - e.g.:
{
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies": {
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10015",
"Microsoft.AspNetCore.TestHost": "1.0.0-rc2-final",
"WebApp": "*"
},
"frameworks": {
"net461": { }
}
}
Create a unit test in class library that uses the web application:
public class IntegrationTests
{
[Fact]
public void Test()
{
var builder = new WebHostBuilder();
builder.UseStartup<Startup>();
}
}
Expected behavior
Tests are executed properly
Actual behavior
Project WebApp (.NETFramework,Version=v4.5.1) was previously compiled. Skipping compilation.
Project WebApp.Tests (.NETFramework,Version=v4.6.1) will be compiled because inputs were modified
Compiling WebApp.Tests for .NETFramework,Version=v4.6.1
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.4138420
xUnit.net .NET CLI test runner (32-bit win81-x86)
Discovering: WebApp.Tests
Discovered: WebApp.Tests
Starting: WebApp.Tests
System.BadImageFormatException : Could not load file or assembly 'WebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Stack Trace:
at WebApp.Tests.IntegrationTests.Test()
Finished: WebApp.Tests
=== TEST EXECUTION SUMMARY ===
WebApp.Tests Total: 1, Errors: 0, Failed: 1, Skipped: 0, Time: 0,193s
Environment data
dotnet --info
output:
.NET Command Line Tools (1.0.0-preview1-002702)
Product Information:
Version: 1.0.0-preview1-002702
Commit Sha: 6cde21225e
Runtime Environment:
OS Name: Windows
OS Version: 6.3.9600
OS Platform: Windows
RID: win81-x64
Issue Analytics
- State:
- Created 7 years ago
- Comments:30 (1 by maintainers)
Top Results From Across the Web
dotnet test with xUnit and full .NET framework causes ...
I can confirm that after moving a project to VS17 and csproj I constantly get System.BadImageFormatException when running from the command line.
Read more >System.BadImageFormatException when running XUnit ...
System.BadImageFormatException when running XUnit 2.2.0 unit test in VS 2017 against a full .net framework asp.net core project.
Read more >How to fix System.BadImageFormatException
BadImageFormatException is usually due to bitness. One project is 64 bit and the the other is 32 bit. Make sure both project target...
Read more >Can't debug xunit tests under windows or mac : RIDER-49039
I can't debug anymore any xunit test with Jetbrains Rider ever in Mac or Windows. ... System.BadImageFormatException: Could not load file or assembly ......
Read more >Test runner won't execute .NET core tests in 32 bit
Hello I have the following scenario. Test Subject: A dotnet standard class library which accesses a managed dll. This dll needs to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Visual Studio Fix
Menu Bar -> Test -> Test Settings -> Default Processor Architecture -> X64
After upgrading my .NET Core project which targets net461 to csproj I have this issue again when trying to run dotnet test in the command line it always runs the x86 build.