Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if a .NET assembly was built for x86 or x64?

I've got an arbitrary list of .NET assemblies.

I need to programmatically check if each DLL was built for x86 (as opposed to x64 or Any CPU). Is this possible?

like image 849
Judah Gabriel Himango Avatar asked Nov 06 '08 22:11

Judah Gabriel Himango


People also ask

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

Run the application and launch the Task Manager to know if the process runs in 32-bit mode or 64-bit mode on a 64-bit machine. When "*32" is added to the 'image name', the process is running in 32-bit mode. Otherwise it is running in 64-bit mode.

Which .NET framework should I use x64 or x86?

Application ( exe file) should run on x64 or ia64 or x86 depending on the system. But when you use a library ( dll file) registered as COM it can run even in x86 mode (with x86 applications) on a x64 system.


1 Answers

Look at System.Reflection.AssemblyName.GetAssemblyName(string assemblyFile)

You can examine assembly metadata from the returned AssemblyName instance:

Using PowerShell:

 [36] C:\> [reflection.assemblyname]::GetAssemblyName("${pwd}\Microsoft.GLEE.dll") | fl  Name                  : Microsoft.GLEE Version               : 1.0.0.0 CultureInfo           : CodeBase              : file:///C:/projects/powershell/BuildAnalyzer/... EscapedCodeBase       : file:///C:/projects/powershell/BuildAnalyzer/... ProcessorArchitecture : MSIL Flags                 : PublicKey HashAlgorithm         : SHA1 VersionCompatibility  : SameMachine KeyPair               : FullName              : Microsoft.GLEE, Version=1.0.0.0, Culture=neut...  

Here, ProcessorArchitecture identifies target platform.

  • Amd64: A 64-bit processor based on the x64 architecture.
  • Arm: An ARM processor.
  • IA64: A 64-bit Intel Itanium processor only.
  • MSIL: Neutral with respect to processor and bits-per-word.
  • X86: A 32-bit Intel processor, either native or in the Windows on Windows environment on a 64-bit platform (WOW64).
  • None: An unknown or unspecified combination of processor and bits-per-word.

I'm using PowerShell in this example to call the method.

like image 180
x0n Avatar answered Oct 07 '22 15:10

x0n