R Swasey
R Swasey

Reputation: 307

How to change ReSharper unit test architecture to x64?

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?

Upvotes: 9

Views: 7358

Answers (7)

mrfelis
mrfelis

Reputation: 765

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.

Upvotes: 0

Travis Quirk
Travis Quirk

Reputation: 106

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.

Upvotes: 0

nightcoder
nightcoder

Reputation: 13519

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

Upvotes: 9

Chris Marisic
Chris Marisic

Reputation: 33118

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

Upvotes: 0

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31651

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

Upvotes: 2

Valentin Kuzub
Valentin Kuzub

Reputation: 12093

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.

Upvotes: 3

citizenmatt
citizenmatt

Reputation: 18583

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.

Upvotes: 12

Related Questions