Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target 4.5.1 and Any CPU runs as 32 bit on x64, 4.5 runs as 64 bit, Why?

Tags:

Visual Studio target 4.5.1 and Any CPU runs as 32 bit on x64, but when targeting 4.5 and Any CPU it will run as 64 bit on x64 system. What has changed in 4.5.1 to make it run in WOW mode?

Hope this makes sense...

like image 242
Richard.Davenport Avatar asked Jan 30 '14 16:01

Richard.Davenport


2 Answers

Nothing changed in .NET 4.5.1 that affects the bitness of the process.

A very common trap is that programmers pay too much attention to the Platform name. Prominently displayed in the Build + Configuration Manager dialog for example. The name is irrelevant for managed projects. It only matters to the kind of projects that generate code differently based on the Platform selection. C++ projects.

What's worse is that the default Platform name changed between different VS versions. It always used to be AnyCPU. Then it was changed to x86 in VS2010. That caused massive confusion so it was changed back to AnyCPU in VS2012.

The real setting that has an effect is in Project + Properties, Build tab, Platform target setting for the C# IDE. For VS2012 and up also the "Prefer 32-bit" checkbox. Only for the EXE project, it runs first and locks-in the bitness. If you pick x86 (or tick the box) then the CLR is instructed to use the x86 jitter instead of the x64 jitter.

The "Prefer 32-bit" checkbox is turned on by default for a new project. So you already automatically have a mismatch between the Platform name of AnyCPU and the actual bitness of the running process. Oh joy.

like image 108
Hans Passant Avatar answered Sep 28 '22 03:09

Hans Passant


I'm not sure when Visual Studio added the option to "Prefer 32-bit" but this was checked. Hopefully someone won't make the same noob move I did and check the project settings. Thanks @T.S.

like image 25
Richard.Davenport Avatar answered Sep 28 '22 05:09

Richard.Davenport