Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 649
MK. Avatar asked Jul 27 '11 15:07

MK.


People also ask

How do you tell if .NET application is 32 or 64-bit?

If you're trying to check whether or not a running application is running in 32-bit or 64-bit mode, open task manager and check whether or not it has an asterisk (*32) next to the name of the process.

Is .NET framework 32 or 64-bit?

NET Framework 1.0 or 1.1 are treated as 32-bit applications on a 64-bit operating system and are always executed under WOW64 and the 32-bit common language runtime (CLR). 32-bit applications that are built on the . NET Framework 4 or later versions also run under WOW64 on 64-bit systems.

Which. net x64 or x86?

What is the difference between x86 and x64? As you guys can already tell, the obvious difference will be the amount of bit of each operating system. x86 refers to a 32-bit CPU and operating system while x64 refers to a 64-bit CPU and operating system.

Is Visual Studio x64?

Visual Studio 2022 on Windows is now a 64-bit application.


2 Answers

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.

like image 194
David Heffernan Avatar answered Oct 22 '22 19:10

David Heffernan


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

like image 3
James Johnston Avatar answered Oct 22 '22 19:10

James Johnston