Application runs as x86 in unit tests in Visual Studio, but runs as x64 when it stands alone

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

Jon Skeet
people
quotationmark

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.

people

See more on this question at Stackoverflow