MK.
MK.

Reputation: 34597

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 due to failure to load a 32bit DLL. What could cause this behavior?

Upvotes: 8

Views: 1501

Answers (4)

Zan Lynx
Zan Lynx

Reputation: 54393

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

Upvotes: 0

BQ.
BQ.

Reputation: 9423

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

Upvotes: 3

James Johnston
James Johnston

Reputation: 9492

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

Upvotes: 3

David Heffernan
David Heffernan

Reputation: 613592

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.

Upvotes: 19

Related Questions