My understanding is that a .NET application is platform independent, so pure .NET code should run either on a x86 or on a 64-bit machine. Unless your .NET code call some native code, then it is platform dependent. Is that true?
.NET applications can be compiled as targeting x86, x64, or "Both". Typically, you'd target just one platform if you rely on a COM control that is not available for the other platform, etc.
Your code can be compiled to be fully platform independent, or you can target a specific platform. The standard recommendation is to leave libraries architecture-neutral (that is, "Any CPU") and target x86 for executables. The reasons why Visual Studio 2010 uses this approach by default are explained here: AnyCPU executables are usually more trouble than they're worth:
- Running in two very different modes (x64 and x86) increases product complexity and the cost of testing.
- 32-bit tends to be (a little) faster anyway.
- Some features aren't available in x64.
- If more than 4 GB address space would be useful, the right thing to do is to target just x64 and avoid the cost of supporting two platforms.
Of course, if you just target x86 then your code would still run on x64 through WoW64.
Yes, what you say is true. Pure .NET code is platform independent ("Any CPU" in Visual Studio) unless external libraries (COM and P/Invokes as far as I know) is used. Then your platform must match the one used to build the external libraries.
The article Back to Basics: 32-bit and 64-bit confusion around x86 and x64 and the .NET Framework and CLR explains the differences pretty well.