tags:

views:

598

answers:

1

If I have a "Any CPU" compiled .NET app, it will run in 64bit mode on a 64bit OS.

But if I, for whatever reason, wants to force this app to run in 32bit mode. (As if it were compiled using "x86"). Recompiling is not an option, so is this possible to config at run time ? With the .manifest file perhaps?

+6  A: 

I believe you can do this with CorFlags.exe

Something like:
CorFlags yourassembly.exe /32BIT+

Note that if the assembly is strong named you will also have to use the /force option which breaks the strong naming, so you'll then have to resign the assembly.

Simon P Stevens
Well, that's is unfortunately not feasible. The app in question is strong named and distributed to end users (consumers), and re-signing is not really an option either. Too bad.
Magnus Johansson
You can set the CLR to skip strong name verification for a specified assembly. Using "sn.exe -Vr assemblyname" (-Vu to re-enable). Obviously this would have to be run on the customers machine. I wouldn't really recommend this though as disabling strong name verification basically punches a security hole in the CLR, any assembly could be copied over your app and would receive full trust automatically (See: http://msdn.microsoft.com/en-us/library/k5b5tt23.aspx). My recommendation is don't mess with this, find a way to do a re-compile, or don't do it.
Simon P Stevens
@Simon P.Stevens, I agree with you on all points. My hope were that it could be an entry in the manifest file that I could distribute. But that seems not the case.
Magnus Johansson
I think the corflags field is in the manifest file, but the manifest file makes up part of the signed assembly too, so changes to it break the signing. I suppose it might be possible to distribute a separate manifest file and somehow get your app to ignore the one embedded in it. Perhaps it's something you could try. See here: http://blogs.msdn.com/dsvc/archive/2008/06/28/x86-x64-ia64-any-cpu.aspx it mentions the actual fields in the manifest file. Let me know if you manage to get this working. I'd be quite interested in how you did it.
Simon P Stevens