How do exes/dlls generated with the /platform:x switch interact?

Published 08 April 05 11:05 AM | joshwil 

[fixed typo: 9:37am]

I received a question about this recently, so i figured i'd elaborate here with a little example...

 

Let's assume we have the following three dlls:

   anycpu.dll      -- compiled "any cpu"

   x86.dll           -- compiled "x86"

   x64.dll           -- compiled "x64"

 

And the following three exes:

   anycpu.exe     -- compiled "any cpu"

   x86.exe          -- compiled "x86"

   x64.exe          -- compiled "x64"

 

What happens if you try to use these exes and dlls together? We have to consider two possible scenarios, running on a 32-bit machine and running on a 64-bit machine...

 

On a 32-bit x86 machine:

anycpu.exe -- runs as a 32-bit process, can load anycpu.dll and x86.dll, will get BadImageFormatException if it tries to load x64.dll

x86.exe -- runs as a 32-bit process, can load anycpu.dll and x86.dll, will get BadImageFormatException if it tries to load x64.dll

x64.exe -- will get BadImageFormatException when it tries to run

 

On a 64-bit x64 machine:

anycpu.exe -- runs as a 64-bit process, can load anycpu.dll and x64.dll, will get BadImageFormatException if it tries to load x86.dll

x86.exe -- runs as a 32-bit process, can load anycpu.dll and x86.dll, will get BadImageFormatException if it tries to load x64.dll

x64.exe -- runs as a 64-bit process, can load anycpu.dll and x64.dll, will get BadImageFormatException if it tries to load x86.dll

 

Comments

# steven said on April 8, 2005 11:25 AM:
Surely you mean x86.exe on 64-bit will get a BIFE when it tries to load x64.dll, rather than x86.dll?
# joshwil said on April 8, 2005 11:34 AM:
Yep! Typo fixed, thanks for the catch.
# Steven said on April 27, 2005 6:06 AM:
Is there a difference if compiling with VS.NET 2005 Standard vs. Professional?

The comparison card says that Standard does not support a 64-bit compiler. So what would happen if you select anyCpu using the Standard edition?
# Steven said on April 27, 2005 7:46 AM:
One more bit of info regarding my last query: We're using C# if that makes any difference.

Regards.
# joshwil said on April 29, 2005 11:41 AM:
Steve --

I'm in the process of writing up a blog entry to address your questions and the more general case of "what does it take to compile for 64-bit". I will probably post it early next week.

-josh
# Josh Williams said on May 6, 2005 3:20 PM:
In a number of blog entries I have discussed how on 64-bit machines .Net applications can run as either...
# Flipping bits on managed images to make them load with the right bitness... « Millicent Carr News said on May 21, 2007 1:13 AM:

PingBack from http://millicentboh.wordpress.com/2007/05/21/flipping-bits-on-managed-images-to-make-them-load-with-the-right-bitness/

# Famous Quotes » Brad Abrams : The SLAR (vol2) on System.BadImageFormatException said on January 4, 2008 10:30 PM:

PingBack from http://famousquotes.247blogging.info/?p=320

# Function arguments « Vivek Weblog said on March 9, 2008 12:31 AM:

PingBack from http://vivekwin.wordpress.com/2008/03/08/function-arguments/

# Asp.net interview questions with answers|Framework|Basic and advance | DukhSukh said on September 25, 2008 1:54 PM:

PingBack from http://www.dukhsukh.com/2008/09/aspnet-interview-questions-with-answersframeworkbasic-and-advance/

# C-Sharp FAQ’S « Praveen.khade’s said on March 16, 2009 3:23 AM:

PingBack from http://praveenkhade.wordpress.com/2009/03/16/c-sharp-faqs/

New Comments to this post are disabled
Page view tracker