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?

4

7 回答 7

11

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.

于 2013-10-02T07:59:29.673 回答
9

我尝试了在 Google 和 StackOverflow 上找到的不同方法(包括本主题中的其他答案),但对我有用的是:

ReSharper 的单元测试会话窗口 -> 在顶部面板上将平台下拉菜单设置为 64 位。

在此处输入图像描述

于 2015-12-29T19:46:02.210 回答
3

我的解决方案太老套了,但那是唯一对我有用的东西

我放置了一份vstest.executionengine.x86.exe用于备份的副本,并放置了一个重命名的vstest.executionengine.exe(64 位版本)而不是旧的 32 位版本。

于 2014-07-09T00:46:42.857 回答
2

我们在尝试为 Sharepoint 2007 设置 MSTEST 时遇到了类似的问题- 它会继续在 x86 而不是 x64 中运行。实例化SPSite一直说“找不到http://server:port/的 Web 应用程序”。

选项 1 - 分配适当的活动测试设置

我开始替换@valentin-kuzub 建议的 EXE 以确认它可以工作 - 但后来意识到我们激活了错误的测试设置文件 - 有 (2)Local.testsettingsTraceAndTestImpact.testsettings. 其中之一被设置为使用 x86 而不是针对 x64。

选项 2 - 配置 RunSettings

另一种选择是testSettings切换到runSettings分配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>

选项 3 - 使用测试设置默认架构

最后一个选项(您已经尝试过)在选项 #2 的 XML 注释中 -> 您也可以从菜单Test -> Test Settings -> Default Processor Architecture -> x64更改它。

在此处输入图像描述

于 2015-01-16T17:23:25.500 回答
0

使用高内存代码时,您可能会发现需要更改 R# 测试运行器配置以包含

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

您可以在以下位置找到此文件

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

此路径可能取决于 Visual Studio 版本,并且可能因 R# 版本而异。此特定路径是带有 Resharper 9.1 的 Visual Studio 2013。Resharper 10 的经常性问题。配置文件的位置未更改。https://youtrack.jetbrains.com/issue/RSRP-446178

于 2015-04-28T20:19:21.573 回答
0

使用 Visual Studio 2015,我发现 x86 和 x64 设置都会导致此问题。解决方案是关闭并重新启动 Visual Studio。

于 2017-04-17T18:50:35.103 回答
0

我刚刚使用 ReSharper 和 MsTests 遇到了这个问题 - 错误“单元测试运行器无法运行不兼容的目标平台的测试”。

我们的问题是没有构建测试项目。

修理:

  1. Build

  2. Configuration Manager

  3. 确认Build已打勾。

在您的解决方案配置之间切换,以确认它已在所有配置中构建。

于 2016-08-18T02:53:33.177 回答