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


[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 (11)

  1. steven says:

    Surely you mean x86.exe on 64-bit will get a BIFE when it tries to load x64.dll, rather than x86.dll?

  2. joshwil says:

    Yep! Typo fixed, thanks for the catch.

  3. Steven says:

    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?

  4. Steven says:

    One more bit of info regarding my last query: We’re using C# if that makes any difference.

    Regards.

  5. joshwil says:

    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

  6. In a number of blog entries I have discussed how on 64-bit machines .Net applications can run as either…