Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadImageFormatException building solution with unmanaged projects #302

Closed
MaxKot opened this issue Feb 16, 2017 · 6 comments · Fixed by #398 or #592
Closed

BadImageFormatException building solution with unmanaged projects #302

MaxKot opened this issue Feb 16, 2017 · 6 comments · Fixed by #398 or #592
Assignees
Milestone

Comments

@MaxKot
Copy link

MaxKot commented Feb 16, 2017

I have a solution with both managed and native projects. NUnit adapter seems to try to load a native DLL and fails whenever I rebuild the project. You can see the solution here: Log4JDash.

Error message (Log4JParserC.dll is an unmanaged library and Log4JDash.exe is an unmanaged application):

------ Discover test started ------
NUnit Adapter 3.7.0.0: Test discovery starting
Assembly contains no NUnit 3.0 tests: D:\develop\Log4JDash\src\Log4JDash.Web\bin\Log4JDash.Web.dll
Assembly contains no NUnit 3.0 tests: D:\develop\Log4JDash\src\Log4JParserDashNet\bin\x86\Release\Log4JParserDashNet.exe
Assembly contains no NUnit 3.0 tests: D:\develop\Log4JDash\src\Log4JParserNet\bin\x86\Release\Log4JParserNet.dll
Error: Unable to get runner for this assembly. Check installation, including any extensions.
BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
Assembly not supported: D:\develop\Log4JDash\src\Release\Log4JDash.exe
Error: Unable to get runner for this assembly. Check installation, including any extensions.
BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
Assembly not supported: D:\develop\Log4JDash\src\Release\Log4JParserC.dll
NUnit Adapter 3.7.0.0: Test discovery complete
========== Discover test finished: 27 found (0:00:00,3920224) ==========

Visual Studio info:

Microsoft Visual Studio Community 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055

Similar issue is also reported by @anttirt:

I have the same issue as MaxKot; it's related to #248.

The issue is otherwise benign except that the Error log causes focus to switch to the Tests section in the output window after every build of the solution, which can be very annoying. :)

The NUnit runner should somehow detect that a project is a native code project and skip it without emitting an error message, but I don't know if there's an API for that off the top of my head. The built in test discoverer for Visual Studio has the following to say:

Test run will use DLL(s) built for framework Framework45 and platform X86. Following DLL(s) will not be part of run: 
my_native_project.exe is built for Framework None and Platform X64.

So perhaps skipping "assemblies" with Framework = None would do the trick?

I don't have time to experiment with this right now but may take a look at it later this week.

@markusrt
Copy link

I face the same issue. We execute our tests using vstest.console.exe and unfortunately this error causes the test run to fail despite there are no NUnit tests involved.

I.e. we execute a native MSTest Dll and all tests run fine (via MSTest). Then the vstest.console.exe asks all other adapters if they find any tests for the given assembly. The NUnit 3 adapter returns an error, as it is not able to load the assembly.

I debugged the issue and ended up with the following stack trace:

 at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders(UInt16& subsystem, UInt16& dll_characteristics)
 at Mono.Cecil.PE.ImageReader.ReadImage()
 at Mono.Cecil.PE.ImageReader.ReadImageFrom(Stream stream)
 at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters)
 at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
 at NUnit.Engine.Services.RuntimeFrameworkService.ApplyImageData(TestPackage package)
 at NUnit.Engine.Services.RuntimeFrameworkService.SelectRuntimeFramework(TestPackage package)
 at NUnit.Engine.Runners.MasterTestRunner.InitializePackage()
 at NUnit.Engine.Runners.MasterTestRunner..ctor(IServiceLocator services, TestPackage package)
 at NUnit.Engine.TestEngine.GetRunner(TestPackage package)
 at NUnit.VisualStudio.TestAdapter.NUnitTestAdapter.GetRunnerFor(String assemblyName) 

Same as reported in #248 the adapter version 3.4.1 works fine, e.g. ignores the native assembly.

@OsirisTerje
Copy link
Member

I tried to repro this using the Log4JDash sln by @MaxKot (the link in 1st post) Using the 3.7 adapter, it works with no errors. If you still have this issue @tuxxilla , can you provide a small repro sln ?

@OsirisTerje OsirisTerje added the confirm We need a separate confirmation of this issue label Jun 24, 2017
@markusrt
Copy link

@OsirisTerje Please find attached a test solution. See HowToReproduce.txt for details. The error occurs using NUnit Adapter 3.7. It looks as it was introduced after 3.4.1. I tried 3.5 and also observed a crash. Version 2.1.1 works fine (showing warning as expected).

TestSolution.zip

@markusrt
Copy link

@OsirisTerje Are you able to reproduce this issue?

@netx123
Copy link

netx123 commented Jul 25, 2017

I'm using Visual Studio 2017 and am also seeing a similar issue when attempting to build a solution which builds only a c++ application.
I perform a Clean Solution, followed by a Build Solution, the build of the application succeeds, however the output window then jumps to the Tests output showing the following error:

 ------ Discover test started ------
 NUnit Adapter 3.8.0.0: Test discovery starting
 Error: Unable to get runner for this assembly. Check installation, including any extensions.
 BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
 Assembly not supported: C:\XXX\Release\XXX.exe
 NUnit Adapter 3.8.0.0: Test discovery complete
 ========== Discover test finished: 0 found (0:00:00.1987557) ========== 

@OsirisTerje OsirisTerje added is:bug and removed confirm We need a separate confirmation of this issue labels Jul 25, 2017
@OsirisTerje
Copy link
Member

@markusrt Yep, confirmed. There are a couple of issues here, one is that we send out a warning, which should be ok, but we could "hide" it by tuning the verbosity. Then there are 2 more messages which are superfluous, and the error should not be there at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment