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
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • The RISC-V Architecture
  • Architecting a Completely Private VPC Network and Automating the Deployment
  • Building Analytics Architectures to Power Real-Time Applications
  • Single-Tenant vs. Multi-Tenant Architecture: Breaking Down the Key Differences

Trending

  • The Convergence of Testing and Observability
  • Next.js vs. Gatsby: A Comprehensive Comparison
  • AI for Web Devs: Project Introduction and Setup
  • REST vs. Message Brokers: Choosing the Right Communication
  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.

Daniel D'agostino user avatar by
Daniel D'agostino
·
Sep. 09, 15 · Tutorial
Like (1)
Save
Tweet
Share
4.97K 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
  • Architecting a Completely Private VPC Network and Automating the Deployment
  • Building Analytics Architectures to Power Real-Time Applications
  • Single-Tenant vs. Multi-Tenant Architecture: Breaking Down the Key Differences

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: