views:

90

answers:

2

Hey all,

My program (a console application) references several other assemblies (many open-source libraries). I built the assembly with the "Any CPU" option set (using VS2008). When I start the assembly from a 64-bit command prompt on a Windows Server 2008 x64 machine the process always starts as a 32-bit process!

I looked through my references and it appears as though I have a reference for a 32-bit assembly referenced. Could this single reference cause the entire assembly to start as 32-bit?

Also, I use ILMerge to merge all of the referenced assemblies into a single assembly. Maybe that has something to do with it?

Could someone help me figure out what is going on here?

A: 

Yes, this is likely your problem. I would rebuild the assembly as "Any CPU".

Yann Ramin
I did build the assembly that way actually. One of the referenced assemblies is 32-bit only. I guess when I ILMerge everything then ILMerge recognizes the single 32-bit only assembly and sets the entire thing 32-bit?
Jeffrey Cameron
@Jeffrey: Yes. However, if you have a dependency on a 32bit assembly, you will be forced to run 32bit - you can't load a 32bit assembly into a 64bit process.
Reed Copsey
+5  A: 

If you need to load a 32bit assembly, the entire process will need to be 32bit. You could target "Any CPU" for your main application, but then it will run 64bit, and fail at runtime when it tries to load the 32bit assembly.

ILMerge is smart enough to switch the main entry assembly from AnyCPU to x86 if you have an x86 assembly as part of your merge, to prevent this from being a problem.

If you want to run 64bit - you'll need to have all of the assemblies be 64bit or AnyCPU.

Reed Copsey
Excellent. Thanks!
Jeffrey Cameron