Forcing 32-bit CLR Exes on a 64-bit Machine

This one really comes via Mike in that today we were both running the same application on our machines ( same machine spec ) and it was working for me but not for him.

We were foxed until he pointed out that he was running 64-bit ( which I stopped running a little while ago ).

This was an EXE that was using a bunch of .NET CLR assemblies plus a bunch of unmanaged assemblies which seemed to be failing to load.

So…as we remembered from here you can’t have a mixed 32-bit/64-bit process on a 64-bit machine. It has to be all one or the other.

Problem is, if you compile for CLR then generally you choose “any platform” which means Mike’s EXE was choosing to JIT its code as 64-bit but then it was trying to load the unmanaged DLLs which were 32-bit and, hence, failing.

Because we didn’t have the source for this code, we solved the problem by running

corflags.exe /32BIT+

on the executable which changes the header to say to the CLR “I want to JIT 32-bit code please” as though the original builder of the software had selected x86 rather than “Any CPU” in Visual Studio.

This worked a treat in this specific instance – definitely one for me to remember and so I’m storing it here.