How to change ReSharper unit test architecture to x64?
Asked Answered
Y

7

9

In VS2012, I resolved a BadImageException from running a unit test by going to: TEST-> TEST SETTINGS -> DEFAULT PROCESSOR ARCHITECTURE -> x64.

This works in the built in Visual Studio test window but I cannot find the equivalent settings for ReSharper and so I cannot run the unit tests by clicking on the little nodes to left of the test. This is obviously not critical but really annoying.

Does anyone know where these settings are?

Yazbak answered 1/10, 2013 at 20:28 Comment(0)
C
12

ReSharper will run tests with the bit-ness of the test project. So if your test project is AnyCpu, it will run in an AnyCpu host process, which means 32bit on a 32bit system or 64bit on a 64bit system. If you set your project to be 32bit or 64bit specific, ReSharper will run it in a 32bit or 64bit host process.

So, if your production code is 32 bit specific, you should make your test project 32 bit specific, too. If your production code is 64 bit specific, it should work fine, as long as your test project is 64 bit or AnyCpu.

Similarly, it will use the .net runtime of the test project - .net 2 or .net 4.

These defaults work for the vast majority of cases. I've never had to set it manually, but you can override this behaviour, and force a bit-ness or .net framework version. ReSharper 8 has these settings in the Options dialog (Options -> Tools -> Unit Testing). If you set this when a solution is open, it sets it for the current solution. If there isn't a solution open, it becomes the default for all solutions. You can also set this on a per-test run basis in the unit test sessions window. This setting doesn't persist.

Casilde answered 2/10, 2013 at 7:59 Comment(4)
I've set everything that I can think of as x64 and overrode the settings you mentions but still no difference. All very strange. Do you think if it was to do with the 32/64 setting, that the visual studio test would work too? Or do yuo think this feels like a resharper specific issue?Yazbak
I am having same issues - @RSwasey, did you find a solution that works?Constellate
Have you tried enabling the fusion log? This might give you an indication of what assembly is failing. If ReSharper's default AND explicit handling isn't working, I'd suggest something else is at fault. Perhaps create a console app to call one of the unit tests directly - set the console app explicitly to x64 and it should either work (in which case ReSharper has a bug here) or it'll fail, and you'll have less moving parts to figure out where your issue is.Casilde
Doesn't work for me. I still see JetBrains.ReSharper.TaskRunner is run as a 32-bit process :(Dildo
D
9

I tried different things that I found in Google and on StackOverflow (including other answers in this topic), but what worked for me is:

ReSharper's Unit Test Sessions window -> on the top panel set Platform dropdown to 64-bit.

enter image description here

Dildo answered 29/12, 2015 at 19:46 Comment(0)
M
3

My solution is too hacky, but thats the only thing which worked for me

I placed a copy of vstest.executionengine.x86.exe for backup and placed a renamed vstest.executionengine.exe (64bit version) instead of old 32 bit version.

Mercaptopurine answered 9/7, 2014 at 0:46 Comment(0)
R
2

We had a similar issue when trying to setup MSTEST for Sharepoint 2007 - it would keep running in x86 instead of x64. Instantiating SPSite kept saying "The Web application at http://server:port/ could not be found".

Option 1 - Assign Proper Active TestSettings

I started with replacing the EXEs suggested by @valentin-kuzub to confirm it would work - but then realized that we had the wrong Test Settings file active - there were (2) Local.testsettings and TraceAndTestImpact.testsettings. One of them was set to use x86 instead of targeting x64.

Option 2 - Configure RunSettings

Another option is switching from testSettings to runSettings and assigning TargetPlatform.

<RunSettings>
  <!-- Configurations that affect the Test Framework -->
  <RunConfiguration>  
    <!-- [x86] | x64 - You can also change it from menu Test, Test Settings, Default Processor Architecture -->
    <TargetPlatform>x64</TargetPlatform>
    <!-- Framework35 | [Framework40] | Framework45 -->
    <TargetFrameworkVersion>Framework40</TargetFrameworkVersion>
  </RunConfiguration>

Option 3 - Use Test Settings Default Architecture

The last option (which you already tried) is in the XML comments from option #2 -> You can also change it from menu Test->Test Settings->Default Processor Architecture->x64.

enter image description here

Resinoid answered 16/1, 2015 at 17:23 Comment(0)
Z
0

When working with high memory code you may find you need to alter the R# test runner config to include

<runtime>
    <gcAllowVeryLargeObjects enabled="true" />
</runtime>

You can find this file located at

%localappdata%\JetBrains\Installations\ReSharperPlatformVs12\
JetBrains.ReSharper.TaskRunner.CLR45.x64.exe.config

This path is likely dependudant upon Visual Studio version and may vary upon R# version. This specific path is Visual Studio 2013 with Resharper 9.1. Recurrent issue with Resharper 10. Location of config file is unchanged. https://youtrack.jetbrains.com/issue/RSRP-446178

Zilpah answered 28/4, 2015 at 20:19 Comment(0)
B
0

I just ran into this with ReSharper and MsTests - error "unit test runner failed to run tests incompatible target platform".

Our issue was that the test project wasn't being built.

To fix:

  1. Build

  2. Configuration Manager

  3. Confirm that Build is ticked.

Switch between your Solution Configurations to confirm it's being built in all configurations.

Bump answered 18/8, 2016 at 2:53 Comment(0)
N
0

With, Visual Studio 2015, I've found that both x86 and x64 settings will cause this. The solution was to close and restart Visual Studio.

Naughton answered 17/4, 2017 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.