繁体   English   中英

32/64位与.NET可执行文件的混淆

[英]32/64 bit confusion with a .NET executable

我使用C#使用Visual Studio 2005进行可执行构建。 dumpbin报告它是x86,声称它是作为x86目标构建的。 但是,当我尝试执行它时,它会以某种方式变成64位可执行文件,由任务管理器报告,进程资源管理器和procmon显示它加载了Framework64。 并且最终由于未能加载32位DLL而失败。 什么可能导致这种行为?

您正在使用AnyCPU目标构建它。 如果你想要它甚至在64位系统上是x86,那么你必须以x86为目标。

当您以AnyCPU为目标时,加载程序在64位系统上以64位进程运行该进程,在32位系统上以32位进程运行。

在项目属性/构建配置列表中将平台目标从“任何”更改为“x86”。

可以使用corflags.exe强制它以32位运行。

O:\>corflags
Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Usage: Corflags.exe Assembly [options]

If no options are specified, the flags for the given image are displayed.

Options:
/ILONLY+ /ILONLY-     Sets/clears the ILONLY flag
/32BIT+  /32BIT-      Sets/clears the 32BIT flag
/UpgradeCLRHeader     Upgrade the CLR Header to version 2.5
/RevertCLRHeader      Revert the CLR Header to version 2.0
/Force                Force an assembly update even if the image is
                      strong name signed.
                      WARNING: Updating a strong name signed assembly
                       will require the assembly to be resigned before
                       it will execute properly.
/nologo               Prevents corflags from displaying logo
/? or /help           Display this usage message

“什么可能导致这种行为?”

为了在技术上准确回答这个问题,但并不完全符合你的要求,导致这种行为的原因是缺少64位DLL。

为什么程序没有64位版本呢?

几年后我怀疑32位系统将存在于任何地方,除非ARM和ARM系统需要重新编译新的DLL。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM