none
Agnostic executables RRS feed

  • Question

  • Hi

    If I build a simple managed app, for AnyCPU (an agnostic assembly) then it will run as a 64-bit app on a 64-bit OS or a 32-bit app on a 32-bit OS.

    Is there a way to control this? is there a way to force such an executable to run as a 32-bit app on a 64-bit OS?

    Cap'n
    Monday, September 28, 2009 6:27 PM

Answers

  • Mscoree.dll makes that decision.  You can force your app to run in 32-bit mode without setting the platform target by uninstalling the 64-bit version of the .NET framework first.  Using corflags.exe is quicker.

    Hans Passant.
    • Marked as answer by eryang Monday, October 5, 2009 6:50 AM
    Tuesday, September 29, 2009 3:15 PM
    Moderator

All replies

  • Yes, don't use AnyCPU and instead use x86.
    Monday, September 28, 2009 6:46 PM
  • As Adam suggested, you can build your application to target x86 directly.

    Alternatively, you can use CorFlags (with the /32Bits+ argument) to change the executable after it's been compiled.

    Reed Copsey, Jr. - http://reedcopsey.com
    Monday, September 28, 2009 6:47 PM
    Moderator
  • That doesn't answer my question. My question was that I want the exe to be agnostic, I want it to be able to run as 32-bit on 32-bit OS and as 64-bit on 64-bit OS. But in addition I want to be able to force it to starts as 32-bit on a 64-bit OS if I need it to (testing, debugging etc).

    If I build it as x86 then it WONT run as 64-bit on a 64-bit OS, which is what I want it to do if I don't override this.

    Somehow the loader decides whether the managed code should run as 32-bit or 64-bit, it does this now and it does it by examining the host OS. I want to be able to override that and force it run as 32--bit on 64-bit OS on ocassions.

    Thanks

    Cap'n

    • Edited by Captain Kernel Tuesday, September 29, 2009 9:09 AM clarify
    Tuesday, September 29, 2009 9:08 AM
  • It does answer your question in that you cannot change that at runtime. You can only alter your executable by compilation or the CorFlags. By the time your executable is even looked at by Windows to run it it's too late.

    Maybe on XP pre SP1 (is that when it was added?), when .NET PEs weren't natively understood by the OS could you do something, but now Windows runs your EXE like any other. Provider a launcher up that updates the PE info.
    Tuesday, September 29, 2009 1:27 PM
  • Adam

    I appreciate you answering but I must disagree, my question remains unanswered.

    At startup the CLR must decide whether to initialize the first AppDomain as being 32-bit or 64-bit, therefore this decision IS made at runtime if the assembly is built as agnostic.

    As you know the same physical EXE file (if agnostic) will run as a 32-bit AppDomain on my 32-bit OS yet that same EXE will run as a 64-bit AppDomain on my 64-bit OS, so clearly something IS making a decision at runtime.

    My question is therefore: How does one control whether the initial AppDomain is 32-bit or 64-bit?

    I dont want to alter the executable, I simply want to know if there is a public way of doing what the CLR does, namely decide the 'bitness' of an AppDomain when it starts that AppDomain.

    Thanks

    Cap'n
    • Edited by Captain Kernel Tuesday, September 29, 2009 2:11 PM clarify
    Tuesday, September 29, 2009 2:10 PM
  • Mscoree.dll makes that decision.  You can force your app to run in 32-bit mode without setting the platform target by uninstalling the 64-bit version of the .NET framework first.  Using corflags.exe is quicker.

    Hans Passant.
    • Marked as answer by eryang Monday, October 5, 2009 6:50 AM
    Tuesday, September 29, 2009 3:15 PM
    Moderator