c# - 为什么我用 Any CPU 编译的应用程序在我的 64 位机器上作为 32 位进程运行?

标签 c# 64-bit anycpu

为什么我用 AnyCPU 编译的应用程序在我的 64 位机器上作为 32 位进程运行,因此无法与作为 64-位过程?

我有以下代码不能在 x64 操作系统上运行,因为 notepad.exe 是 x64 并且 x86 应用程序无法获取 x64 进程的模块信息:

prc.Modules[0].FileName

.Net 异常抛出我的代码:

System.ComponentModel.Win32Exception (0x80004005): A 32 bit processes cannot access modules of a 64 bit process.

根据本论坛、MSDN 上的许多答案和文章,...,我知道我需要改用 AnyCPU,因为使用 x64 对我没有特别的好处。即使在 AnyCPU 配置上编译时,我的错误仍然存​​在,此外,在 任务管理器 中,我在进程名称的末尾看到一个 (32 位)

(实际上我通过检查性能测试了代码,x64 代码运行速度快了 40 毫秒。没关系,我不希望我的代码运行速度快 40 毫秒:D)

我不知道那是错的。

VS 2011 测试版 (x64)

Windows 8 消费者预览版 (x64)

您真诚的, 佩曼莫塔扎维

最佳答案

虽然提问者接受了答案,但我觉得答案不完整,因为提问者提到他正在使用 Visual Studio 2011,因此假设目标 .Net Framework 是 4.5,关于什么“AnyCPU”的意思。

请引用这两个链接,以更好地了解“AnyCPU”的含义如何随时间发生变化。

  1. http://blogs.microsoft.co.il/sasha/2012/04/04/what-anycpu-really-means-as-of-net-45-and-visual-studio-11/
  2. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/platform-compiler-option

从这些链接中,您可以找到为什么您的应用程序作为 32 位进程运行的问题的答案

On a 64-bit Windows operating system:

Executables compiled with /platform:anycpu32bitpreferred execute on the 32-bit CLR.

这是你的罪魁祸首。

enter image description here

关于c# - 为什么我用 Any CPU 编译的应用程序在我的 64 位机器上作为 32 位进程运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10918366/

相关文章:

visual-studio - MSBuild:避免重复构建任何 CPU 项目引用

c# - 为什么此 C# 代码会使进程崩溃?

c# - 如何在 datagrid C# wpf 中动态行?

python - 为什么我不能导入 nltk?

64-bit - VirtualBox Windows x64 错误 0xc000035a

c# - 使用 OData 在 .NET API 上返回嵌套对象

c# - 依赖项未复制到 bin 文件夹

c - 应该与 32 位和 64 位进程一起工作的 64 位库

c# visual studio build exe with target anycpu 但在调用进程平台(x86/x64)上确定其平台(x86/x64)