2

Info about my setup:

  • Resharper 2016.3.2
  • XUnit 2.2.0
  • VS 2017 RTM
  • Test Project .net 4.5.2
  • Asp.net Core Project .net 4.5.2

Repo Steps:

  1. Create an asp.net core site targeting .net 4.5.2

  2. Add a unit test project or class library to the solution and reference the asp.net project

  3. Create a xunit Fact test that targets a class in the asp.net project

  4. Run the unit test using resharper test runner

Error:

System.BadImageFormatException Could not load file or assembly 'AFAEMS, 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. at AFAEMS.Tests.Class1.return_errors_if_missing_fields()

Notes:

I've done a lot of searching and cannot find any similar issues to this. I can run a unit test with a simple assert that is not targeting the asp.net core class files. I couldn't get the VS test runner to find my xunit tests (maybe b/c resharper test runner is enabled?).

These were things I found but don't indicate how to fix with the new xproj and app.config using MSBuild for VS 2017. https://blogs.msdn.microsoft.com/visualstudioalm/2016/05/30/announcing-mstest-framework-support-for-net-core-rc2-asp-net-core-rc2/

Testing Asp.Net Core on full .NET framework

https://github.com/dotnet/sdk/issues/926

3 Answers 3

4

In Visual Studio change the target from “X86 ” to “Any CPU”.

Also,you will get this error if you try to host an application with a 32-bit assembly reference ,on IIS running on a 64 bit server/machine. To fix this error set "Enable 32 bit applications" flag to true in Advanced settings of the application pool hosting the application in IIS.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

2

I was able to get this fixed by using the following settings in my Resharper unit testing options.

resharper options unit testing

1 Comment

Same here - but I'd also changed to x64 from Test -> Test Settings -> Default Processor Architecture.
0

In my case the only solution was to run XUnit tests project with the x86 Target Platform configuration.

It is possible to be set in unit tests .csproj file.

Just add:

 <PropertyGroup> <PlatformTarget>x86</PlatformTarget> </PropertyGroup> 

This will also work outside of IDE - when running

dotnet test 

in CI/CD pipelines

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.