3

this line of code

Environment.Is64BitProcess

Evaluates to true when my app is running standing alone.

But the same expression evaluates to false when it's running in my unit tests in Visual Studio.

I have chosen "Any CPU" as the solution platform, the machine is 64bit.

Why is this?

enter image description here

Even when I set it like the image above, Resharper still runs it as x86

Cui Pengfei 崔鹏飞
  • 8,017
  • 6
  • 46
  • 87
  • @Luaan not really related. VS can run/debug both x86 and x64 processes just fine. And default test runner can run in x64 mode too (as long as it configured to do so). – Alexei Levenkov Sep 08 '15 at 14:48
  • @Luaan original comment was about relation to VS is x86 - I was trying to highlight the fact that being x86 process does stop VS from dealing with x64 processes. Now since the original comment is gone both of my comments will self-destruct to in 10...9... – Alexei Levenkov Sep 08 '15 at 14:55

1 Answers1

4

That basically says that the unit test runner is starting up as a 32-bit process. How you configure that will depend on which unit test runner you're using (there are many of them).

When you're running your unit tests, any preference your application assemblies have in terms of architecture will be ignored compared with the unit test runner's configuration - whereas when you're running standalone, the build configuration (e.g. "AnyCPU prefer x86" or just "AnyCPU") will be relevant.

If you really, really need your unit tests to be running in x64, you should look at how you run them - and if you can't change how they're run in VS, you might at least be able to run them in a standalone runner which may well support x64 more easily.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 2
    VS 2013: Tests->Tests Settings -> Default Processor Architecture -> x64 should select x64 for default VS test runner. For older once setting may be in other place - http://stackoverflow.com/questions/5880337/run-tests-in-64-bit – Alexei Levenkov Sep 08 '15 at 14:46
  • @Alexei, yes, that option is chosen, but Resharper unit test runner is still running my test project in x86, even though the test project is set to any cpu on a 64bit machine. and in resharper settings, i have chosen default platform architecture as automatic based on test project's target platform – Cui Pengfei 崔鹏飞 Sep 08 '15 at 14:55
  • @CuiPengFei "any CPU" by default comes with "prefer 32-bit" - make sure it is not set - http://stackoverflow.com/questions/12066638/what-is-the-purpose-of-the-prefer-32-bit-setting-in-visual-studio-2012-and-how – Alexei Levenkov Sep 08 '15 at 14:59
  • @AlexeiLevenkov, yes, but that is only available for .net4.5+ in vs 2015, right? I am using .net4. and that option is grayed. – Cui Pengfei 崔鹏飞 Sep 08 '15 at 15:00
  • @CuiPengFei VS2012+, but that option is only for EXE (as DLL inherits bit-ness from its process). If you require x64 - either make DLL x64 only, or make sure to configure processes/test runners that load your DLL to run x64 (and not try to "detect"/default to anything). – Alexei Levenkov Sep 08 '15 at 15:07