tags:

views:

190

answers:

1

Let's say that when i've compiled a managed assembly, i've forced it to be 64 bit (using the configuration manager). and let's say, that after the compilation i want to run that application as a 32bit process. can i force it to be 32bit again? i tried to play around and edit the PEHeader (the Machine and 32BitOnly fields), but the application won't start on a 32bit platform.
is there a difference in the produced IL when i force the compile it as 64bit? (in comparison to AnyCPU)

A: 

I don't believe there is a difference in the IL, the difference in the the non-managed headers. 64 bit mode compiles an EXE with a PE32+ format header (that is 64 bit). So just changing a flag won't change the actual format of the EXE. That's the reason you get the error that it is not a valid 32bit applications, it's not, it's a 64 bit application and 32 bit Window's can't parse the PE32+ header.

You would have to completely rewrite the EXE to PE32 format, so it probably isn't possible.

Can't you just recompile or is this just for your own interest?

shf301
own interest.. why would the compiler use a PE32+ format? why not to use the regular format and just add the appropriate flags in the .Net section of the header? (like it does with AnyCPU/32bit). What kind of benefits are there?
I have no idea. My guess is that it was a cheap way to make sure the code only ran on 64 bit systems - by making a file that only 64 bit OS would read, they didn't have to code anything in the run time to handle that case.
shf301