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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Architecture Review Boards for Generative AI: A Framework for Governance, Risk Management, and Responsible Adoption
  • A Reference Architecture for Constrained AI-Assisted Design
  • GenAI Security Gateway: An End-to-End Architecture
  • Your Cloud Diagram Is Already Out of Date: An Operating Model for Continuous Security Architecture

Trending

  • Why Your AI Agent Works in the Demo and Fails in Production
  • The Twelve-Factor Agents: Building Production-Ready LLM Applications
  • The Window Closes: Why I Switched to Kotlin Before the Codebase Got Too Big
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Sep. 09, 15 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Architecture Review Boards for Generative AI: A Framework for Governance, Risk Management, and Responsible Adoption
  • A Reference Architecture for Constrained AI-Assisted Design
  • GenAI Security Gateway: An End-to-End Architecture
  • Your Cloud Diagram Is Already Out of Date: An Operating Model for Continuous Security Architecture

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook