65.9K
CodeProject is changing. Read more.
Home

How to Determine if a .NET Assembly was Built for x86 or x64?

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (5 votes)

Apr 14, 2014

CPOL
viewsIcon

26941

downloadIcon

473

An application to read assembly name information c#.net reflection

Introduction

This post demonstrates how to read .NET assembly name metadata.

Background

Originally, I require to detect whether the target platform for any .NET assembly is built? After digging, I end up with creating a small Winform application which can display some Assembly name attributes.

Using the Code

This code can be utilized by firstly calling the GetAssemblyName method in AssemblyName class in System.Reflection namespace (as shown below) and then fetching the different attributes of the assembly to be analyzed.

Read assembly metadata using reflection (System.Reflection):

var assemblyInfo = AssemblyName.GetAssemblyName(textBoxAssemblyFilePath.Text); 
var assemblyName = assemblyInfo.Name 
var assemblyVersion = assemblyInfo.Version 
//similarly to find process architecture  
var assemblyArchitecture = assemblyName.ProcessorArchitecture; 

Using the Sample Application

To find the process architecture of the .NET Assembly, just download the sample application with this post and execute.

Select the assembly to analyse and click on 'Read Assembly Metadata'.

The description text box will show the metadata for which I have programmed. If required, you can do some more research to read other metadata associated with the assembly like - Culture Info, Signing information, private and public key information, etc. (See the screenshot below.)

Reference Link