Targetting x86 vs AnyCPU when building for 64 bit window OSes

Posted by Mr Roys on Stack Overflow See other posts from Stack Overflow or by Mr Roys
Published on 2010-06-01T04:24:16Z Indexed on 2010/06/01 4:33 UTC
Read the original article Hit count: 262

Filed under:
|

I have an existing C# application written for .NET 2.0 and targetting AnyCPU at the moment. It currently references some third party .NET DLLs which I don't have the source for (and I'm not sure if they were built for x86, x64 or AnyCPU).

If I want to run my application specifically on a 64 bit Windows OS, which platform should I target in order for my app to run without errors? My understanding at the moment is to target:

  • x86: If at least one third party .NET dll is built for x86 or use p/Invoke to interface with Win32 DLLs. Application will run in 32 bit mode on both 32 bit and 64 bit OSes.
  • x64: If all third party .NET dlls are already built for x64 or AnyCPU. Application will only run in 64 bit OSes.
  • AnyCPU: If all third party .NET dlls are already built for AnyCPU. Application will run in 32 bit mode on 32 bit OSes and 64 bit on 64 bit OSes.

Also, am I right to believe that while targetting AnyCPU will generate no errors when building a application referencing third party x86 .NET DLLs, the application will throw a runtime exception when it tries to load these DLLs when it runs on a 64 bit OS.

Hence, as long as one of my third party DLLs is doing p/Invoke or are x86, I can only target x86 for this application?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about x64