6

Evey now and then I see both x86 and x64 versions of a .NET assembly. Consider the following web part for SharePoint. Why wouldn't the developer just offer a single version and have let the JIT compiler sort out the rest? When I see these kinds offering is it just that the developer decided to create a native image using a tool like ngen in order to avoid a JIT?

Someone please help me out here, I feel like I'm missing something of note.

Updated

From what I got below, both x86 and x64 builds are offered because one or more of the following reasons:

  1. The developer wanted to avoid JITing and created a native image of his code, targeting a given architecture using a tool like ngen.exe.

  2. The assembly contains platform specific COM calls and so it makes no point to build it as AnyCPU. In these cases builds that target different platforms may contain different code.

  3. The assembly may contain Win32 calls using pinvoke which won't get remapped by a JIT and so the build should target the platform it is bound to.

1
  • I thought ngen could only be run on the target machine. Is that not the case anymore?
    – erikkallen
    Jan 18, 2009 at 11:39

3 Answers 3

6

If they are using specific non-.Net API, then there may be two code bases for this, a perfect example is COM controls.

ngen is also another very good reason for this as you mentioned.

1
  • ... and probably P/Invoke stuff too. Jan 17, 2009 at 23:45
6

When you compile a .net application you have to pick a Platform Target in the Build Settings. The choices are AnyCPU, x86 and x64.

A common bug is to specify AnyCPU in a project which includes native DLLs compiled for x86. This will lead to errors when run on 64-bit machines, a good reason to test on a 64 bit machine.

Therefore, to support people who are forced by their other dependencies to build for x86 or x64 directly, the assembly offers both.

0

COM handles marshaling and unmarshaling across 32/64 bit boundaries. However, it does not provide any support for loading the alternative type of binary into the wrong pointerwidth of apartment.

Many assemblies rely on native code (most SQL drivers are written in C or C++, for example). This is incredibly evident for anything using p/invoke; thus, having different pointerwidths compiled and distributed means that the package for the 64-bit version most likely contains 64-bit native DLLs, and the 32-bit version likely contains 32-bit native DLLs. This is the case even if the 32 and 64 bit versions of the assembly are compiled from the same code.

csc will produce the native (pre-JITted) images if you ask it to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.