Target 4.5.1 and Any CPU runs as 32 bit on x64, 4.

2019-01-18 19:07发布

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...

2条回答
神经病院院长
2楼-- · 2019-01-18 19:33

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.

查看更多
放我归山
3楼-- · 2019-01-18 19:39

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.

查看更多
登录 后发表回答