DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Related

  • The RISC-V Architecture
  • Secure DevOps in Serverless Architecture
  • Building Scalable and Resilient UI/UX With Angular and Node.js
  • AI Agent Architectures: Patterns, Applications, and Implementation Guide

Trending

  • Mastering Fluent Bit: Controlling Logs With Fluent Bit on Kubernetes (Part 4)
  • Four Essential Tips for Building a Robust REST API in Java
  • Converting List to String in Terraform
  • Python Automation Testing With Examples
  1. DZone
  2. Software Design and Architecture
  3. Microservices
  4. Determining the Bitness (x86 or x64) of a DLL

Determining the Bitness (x86 or x64) of a DLL

Wondering if that DLL is x86 or X64? Here's how to find out.

By 
Daniel D'agostino user avatar
Daniel D'agostino
·
Sep. 09, 15 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.9K Views

Join the DZone community and get the full member experience.

Join For Free

hello guys and gals!

in this article, we’re going to tackle a pretty frustrating scenario: making sure all your .net assemblies or even native dlls target the same architecture. at the time of writing, applications tend to be targeted at x86 or x64 architectures, or both. however, mixing dlls or executables compiled for different architectures is a recipe for disaster . this kind of disaster, in fact:

bitness-badimageformatexception
that’s a badimageformatexception, saying:

an unhandled exception of type ‘system. badimageformatexception ‘ occurred in microsoft.visualstudio.hostingprocess.utilities.dll
additional information: could not load file or assembly ‘classlibrary, version=1.0.0.0, culture=neutral, publickeytoken=null’ or one of its dependencies. an attempt was made to load a program with an incorrect format.

this is why it’s happening:

bitness-mixed-architecture

that’s a very, very stupid thing to do, having an x64 console application depend on an x86 class library (or dll). remember:

bitness-dont-mix-architectures

great, now you know. but you’re bound to run into the badimageformatexception problem anyway, because while it’s easy to control the bitness of the assemblies in your project, you often depend on dlls provided by third parties, and their own bitness isn’t clearly defined. unfortunately, you can’t rely on rightclick -> properties -> details because that doesn’t give you the bitness at all.

fortunately, however, there are tools you can use to find out what architecture those dlls are compiled for.

let’s start off with .net assemblies. if the dll in question is a .net assembly, you can use the corflags utility to find out the bitness . corflags is part of the visual studio developer tools, so you’ll first need to start a visual studio developer command prompt (see this stackoverflow thread or search windows for corflags.exe in case you can’t find one from the start menu).

once you’ve located corflags.exe or have a visual studio developer command prompt, run corflags.exe with the full path to the dll you want to inspect, and check the 32bit setting in the output:

bitness-corflags










now corflags.exe works great to find out the architecture of a .net assembly, but can’t tell you the architecture of a native dll. this is what happens if you try to use it with sdl2.dll, for instance:

bitness-corflags-native










for unmanaged/native dlls, we can instead use dumpbin . this will spit out a bunch of information, so you can find the architecture quickly if you filter the information by including only the line containing the word “machine”, as the linked stack overflow answer suggests:

bitness-dumpbin











so there you go – this article has presented two different ways to check the bitness or cpu architecture of managed and unmanaged dlls respectively, which helps when troubleshooting those dreaded badimageformatexceptions. in reality this article is a consolidation of the information in the two stack overflow threads linked above, and i would like to thank the authors because i have found their tips useful on many occasions.

this article was originally posted here at programmer’s ranch on 28th september 2014.

64-bit Architecture

Published at DZone with permission of Daniel D'agostino, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • The RISC-V Architecture
  • Secure DevOps in Serverless Architecture
  • Building Scalable and Resilient UI/UX With Angular and Node.js
  • AI Agent Architectures: Patterns, Applications, and Implementation Guide

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: