Why is an 'Any CPU' application running as x86 on a x64 machine?
Asked Answered
C

1

15

I have a Any CPU application installed to Program Files (x86). On one Windows 7 x64 machine, it runs as x64 as expected while on another Windows 7 x64 machine, it runs as x86!

How can this be? I expected it to run as x64 on both machines. What might be the reason and what can I do to always make it run as x64?

Does it matter where I am running it from - Program Files (x86) in my case?

Communism answered 10/6, 2011 at 10:22 Comment(2)
Is the program in "Program Files (x86)" on both machines?Blomquist
@WillA where the program lies isn't important. A 32-bit program can be stored in \Program Files while a 64-bit program can be in \Program Files (x86). They will be all loaded correctly because the instruction set info has been written in the headerBioluminescence
E
13

It's likely that you linked some assemblies that are not Any CPU, but include native code (or are compiled as x86), which cause the entire process to fall back to x86.

To understand how your assemblies are compiled, a related Stack Overflow question that might help is How to determine if a .NET assembly was built for x86 or x64?*.

Note: the location of the executable on the file system does not matter at all.

Eurus answered 10/6, 2011 at 10:28 Comment(6)
But then, how did it manage to run as x64 on a different machine?Tomasz
Wild guess: different versions of the same dependent assembly in the GAC. I ran into this problem with TFS assemblies and I've spent literally days to figure out the problem.Eurus
@Tomasz - for example, if you have referenced drivers (like database drivers), and one user has only got the 32 bit versions installed it will force your app to run as 32 bit as well.Cammi
I have just faced a similar problem. In my case, the fix was easy - on the Build tab of the project Properties, the Prefer 32-bit (just below the Platform target, which called Any CPU) was turned on.Desiccant
Nice one @Viliam. This i was the fix for me.Venesection
Well that's annoying. I had the Active (Debug) configuration selected, and Prefer 32-bit was not checked. I changed the configuration to Debug, and now it's checked? And it stays checked when going back to Active (Debug). Seems like there's a bug with this checkbox sometimes showing it's unchecked when it's not.Endoergic

© 2022 - 2024 — McMap. All rights reserved.