History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: RSRP-71135
Type: Exception Exception
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Victor Kropp
Reporter: Jerry Rubinow
Votes: 12
Watchers: 10
Operations

If you were logged in you would be able to see more operations.
ReSharper

ReSharper repeatably generates BadImageFormatException exception when attempting to run unit tests under certain conditions

Created: 04 Jun 08 21:51   Updated: 26 Jan 10 13:44
Component/s: Unit Testing
Fix Version/s: 5.0
Security Level: Everybody (All jira users)

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 799.16
Checked in Build: 1,539
Fixed in build: 1,539


 Description  « Hide
I reported this in the message board, then saw the request for remaining issues to be put in this DB, so here it is.

We have a solution that has both x86 and x64 builds. When we build the x64 version and try to run unit tests (NUnit) via ReSharper within Studio, we get:

System.BadImageFormatException: Attempted to load a 64-bit assembly on a 32-bit platform. Use ReflectionOnlyLoad() instead if trying to load for reflection purposes.

This is using ReSharper 4.0.799.16 with a build date of 5/13/08. Another computer, running same Studio, same source code, but with ReSharper 3.1.584.3, build date of 2007-12-20 does not have this problem. It runs the unit tests without a problem. We are using the same version of NUnit on both systems. The systems are both 64-bit computers running Windows Vista 64.

Studio info:

Microsoft Visual Studio 2008
Version 9.0.21022.8 RTM
Microsoft .NET Framework
Version 3.5

Installed Edition: Professional

Microsoft Visual C# 2008 91605-270-1501536-60335
Microsoft Visual C# 2008

I saw a post about using coreflags.exe to force builds for a specific platform, which may work for a stopgap solution (although we haven't tried it yet).

I'm happy to provide any other info you may need.



 All   Comments   Work Log   Change History      Sort Order:
Sandy Coyne - 11 Jun 08 22:55
We also have this problem, pretty much exactly as reported. It seems that on our x64 development machines, the unit test runner is strictly 32 bit. We've seen other posts complaining that the unit test runner is strictly x64, so clearly there is some variable that we aren't aware of. How do we configure the unit test runner to use the 64 bit framework or not?

--Sandy


Sandy Coyne - 01 Jul 08 00:57
Clarification: We call out to 64-bit unmanaged code from our assemblies, so they must be run in the framework64. If we compile for AnyCPU, the nunit tests run and then fail with BadImageFormatException when we call out to unmanaged code. If we compile for x64 CPU, the entire unit test assembly fails to start, with the same error.

System details:
Windows Server 2003 x64
Resharper 4.0.818.11
VS TeamSystem 2008 9.0.21022.8 RTM

Any chance you can share which system detail/variable controls which .net framework version/platform is used for running the nunit test runner?


Sandy Coyne - 03 Jul 08 02:21
I found the culprit: In 4.0.818.11, the JetBrains.ReSharper.TaskRunner.exe assembly is compiled 32bit only. Judging by the version related differences surrounding the comments on other related issues on this issue tracker, I imagine that it hasn't always been the case. Can you point us to a compatible TaskRunner that is compiled for AnyCPU? That would help us out greatly.

I just installed 4.0.904.3 and got the same behavior. Not being able to test 64 but code on a 64 bit OS is kinda weak.

--Sandy


Kevin Jones - 04 Aug 08 19:47
One option for this would be to use the "corflags.exe /32BIT-" on the TaskRunner.exe and all of it's dependent assemblies. This will allow the process to execute in x64. I've had pretty good success with this, but please only do this as an act of desperation. If you're resharper installation stops working, it's not my fault.

Mads Nissen - 11 Oct 08 16:39
I'm experiencing the same error. It seems to have occured after I upgraded NUnit from 2.4.7 to 2.4.8. However, uninstalling it and referencing 2.4.7 again did not solve the problem. Here is the stacktrace:

System.BadImageFormatException: Attempted to load a 64-bit assembly on a 32-bit platform. Use ReflectionOnlyLoad() instead if trying to load for reflection purposes.
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, ref StackCrawlMark stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, ref StackCrawlMark stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, ref StackCrawlMark stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at JetBrains.ReSharper.UnitTestProvider.nUnit.NUnitTaskRunner.GetFixtureType(NUnitTestFixtureTask fixture, IRemoteTaskServer server) in c:\Agent\work\3f4db6fd459dabcd\src\UnitTestProvider.nUnit\src\NUnitTaskRunner.cs: line 367
at JetBrains.ReSharper.UnitTestProvider.nUnit.NUnitTaskRunner.Start(IRemoteTaskServer server, TaskExecutionNode node, NUnitTestFixtureTask fixture) in c:\Agent\work\3f4db6fd459dabcd\src\UnitTestProvider.nUnit\src\NUnitTaskRunner.cs: line 239
at JetBrains.ReSharper.UnitTestProvider.nUnit.NUnitTaskRunner.Start(TaskExecutionNode node) in c:\Agent\work\3f4db6fd459dabcd\src\UnitTestProvider.nUnit\src\NUnitTaskRunner.cs: line 29
at JetBrains.ReSharper.TaskRunnerFramework.CurrentAppDomainHost.Execute(TaskExecutionNode node) in c:\Agent\work\3f4db6fd459dabcd\src\TaskRunnerFramework\src\Impl\CurrentAppDomainHost.cs: line 86


Mads Nissen - 11 Oct 08 16:52
I tried the corflags fix (closed all relevant processes etc) but it still wont work:
C:\Program Files (x86)\JetBrains\ReSharper\v4.1\Bin>copy JetBrains.ReSharper.TaskRunner.exe taskrunner.bak
1 file(s) copied.

C:\Program Files (x86)\JetBrains\ReSharper\v4.1\Bin>copy JetBrains.ReSharper.TaskRunnerFramework.dll taskrunnerframework.bak
1 file(s) copied.

C:\Program Files (x86)\JetBrains\ReSharper\v4.1\Bin>corflags JetBrains.ReSharper.TaskRunner.exe /32BIT-
Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.

corflags : error CF001 : Could not open file for writing

C:\Program Files (x86)\JetBrains\ReSharper\v4.1\Bin>corflags JetBrains.ReSharper.TaskRunner.exe /32BIT-
Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.

corflags : error CF001 : Could not open file for writing


Mads Nissen - 11 Oct 08 17:22
My last comment may be related to vista restrictions. I'm allowed to copy the dlls and run corflags on the copies (in the same dir), but I'm not allowed to do anything with the original files.

Mads Nissen - 11 Oct 08 18:26
Tested another project which worked fine. Problem seems to be related to a referenced component "Cablib.dll" that I'm using. This component was build exclusively for 64bit. by using a 32bit version the error disappeared.

Marc Evans - 15 Jul 09 13:49
Just adding another "Me too". In my case it's Oracle (11g) - the Oracle.DataAccess dll has 32 bit and 64 bit versions. The application is built for "Any CPU" and linked to the 64 bit dll.

Running unit tests inside Resharper fails because the test runner can't load the x64 assembly, it wants the x86 version. Linking the x86 version leads to a whole other stack of problems with mixing 32 and 64 bit oracle clients so that's not a viable workaround - the end result is that I can't run / debug any database tests inside Resharper.


scott fluto - 22 Oct 09 21:32
I just retested this using resharper 5.0 build 1519 and Im still getting this error . This is the error Im getting:

System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

This is when its trying to it an interop . Everything is all 64bit since we only support 64 in our application.

Its says its fixed in version 5 but it still seems to be there . Im not sure but if they could look at how it was working in resharper 3.1 since thats the last version that worked in 64 bit mode. Our whole development teem is stuck running with resharper 3.1 because if this so I was really hoping it was fixed in version 5 .

Note that we also use oracle and we get the same error related to OracleDataAccess.dll(64 bit dll) in resharper 5 . It looks like the resharper unit tester doesnt support anything related to 64 bit.

thanks

scott


scott fluto - 19 Nov 09 17:01
I just retested this in our environment and Im still getting the bad format error:

System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

I checked the resharper about and verified I was running build 1536.55 . We are also using oracle now too so we are getting this error using the oracle driver since its also 64bit.

Is there anything else I should be doing to get this working.

thanks

scott


ajg - 19 Nov 09 17:28
I can confirm that this is still open in 1536.

Victor Kropp - 19 Nov 09 17:44
Need to investigate these problems.
In our test environment everything is working well.

Victor Kropp - 23 Nov 09 15:19
Unit Test Runner now works correctly when using native dlls.

scott fluto - 24 Nov 09 16:32
I just retests this in build 1539.18 and Im still getting this error doing an interop call to a 64bit dll:

System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)


Victor Kropp - 25 Nov 09 14:01
Please, check your project settings, is it compiled for "Any CPU" or "x64"?

scott fluto - 25 Nov 09 16:55
We have about 100 projects in our solution and they are all set to Any CPU , should that make a difference?

scott fluto - 25 Nov 09 19:57
Just to let you know, I tried changing it from AnyCPU to x64 and it worked. Since AnyCPU is valid , if you are picking on this
couldnt you check the operating system type if its AnyCPU since it will jit compile to 32 or 64 based on this
if its set to AnyCPU anyhow.

Victor Kropp - 15 Jan 10 15:24
There are some fixes related to this problem in build 1753.

scott fluto - 15 Jan 10 16:23
I just tried the most recent build 1573 and it all works ok now, even with it set to AnyCPU .

thanks

scott


ajg - 26 Jan 10 13:44
Unfortunately with build 1602 tests in x86 assemblies are now not running (file not found exception on Win7 x64 with VS2010).

After switching the assembies to AnyCPU everything works fine (this won't work for all my assemblies).