开发者

32/64 bit confusion with a .NET executable

I have an executable build with Visual Studio 2005 using C#. dumpbin reports that it is x86 and it is claimed that it was built as a x86 target. However, when I try executing it, it somehow becomes a 64bit executable as reported by task manager, process explorer and procmon shows that it loads Framework64. And it fails eventually d开发者_运维技巧ue to failure to load a 32bit DLL. What could cause this behavior?


You are building it with the AnyCPU target. If you want it to be x86 even on a 64 bit system, then you must target x86.

When you target AnyCPU, the loader runs the process as a 64 bit process on a 64 bit system, but a 32 bit process on a 32 bit system.


Change the platform target from "Any" to "x86" in the project properties / build configuration list.


One can use corflags.exe to force it to run as 32-bit.

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


"What could cause this behavior?"

To be techically accurate in answering this question, but not quite in the spirit you asked, what causes this behavior is the lack of the 64-bit DLL.

Why doesn't the program have a 64-bit version of it?

In a few years I doubt 32-bit systems will exist anywhere except as ARM and ARM systems will need new DLLs to be recompiled anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜