none
VS 11 / .Net 4.5 - Prefer32Bit, x86 vs AnyCPU RRS feed

  • Question

  • Hello All !

    So we are currently developing an application with a third party library for WPF controls targetting .Net 4.0, here is our story  and the associated question.

    Once upon a time, everything was going right - well as usual i should said ;)

    But one of the developer installed VS 11 Beta on its x64 win7 dev machine and our application started to crash with an interesting exception emitted within the 3rd pary library: Operation could destabilize the runtime
    So when I said started to crash, it was exactly the same code coming from the TFS 2010 build  system which was working perfectly on other dev machine.
    Moreover  our initial test under win8 gave the same result.


    We tried to isolate the problem, and here is the result :
    * We create a new project under VS 11 targetting WPF and use our 3rd party control.
    Application crashes
    * Change to target .Net 4.0
    Application works
    * Changed back to target .Net 4.5 
    Application still working !


    So we did a diff of the project file between before and after changing to target .Net 4.0 and it seems a new project property was introduce :     <Prefer32Bit>false</Prefer32Bit>


    The solution for our application was to generate the executable to target any cpu instead of x86 within our VS 2010 project. This change made the app running on Win7 x64 with VS 11 Beta installed
    Remark: we also played with corflags and setting the 32bit flags to false made the application working where as true was crashing.


    So here is the questions :
    Any more information about this Prefer32Bit into the project file ? And seems there is the associated checkbox under the platform combobox in the project editor but it's always disabled.
    Previously it was recommended to target x86 for the executable and any cpu for all other assemblies. Is there any change in this rule when thinking of Win8 and .Net 4.5 ?


    Remark: we are also thinking there is a problem with the 3rd party library, we are going to have a discussion with them but this is out of this topic.

    edit: formating

    Friday, March 23, 2012 5:47 AM

Answers

  • Prefer32Bit flavour was introduced to allow applications target all 32-bit platforms (incl. ARM). It will run on x86, on ARM and on amd64 (in WOW64).
    The information is stored PE file header (as flag COMIMAGE_FLAGS_32BITPREFERRED - see corhdr.h) and can be change/viewed by corflags.ex tool as you discovered.

    Before this new flavour/flag was introduced you had only options x86Only = COMIMAGE_FLAGS_32BITREQUIRED (which would run on x86 and on amd64 [in WOW64], but not run on ARM), or AnyCPU (which would run on x86, on am64 [as 64-bit process] and also run on ARM).
    As you can see the combination of Prefer32Bit could not be achieved without this new flag.

    The flag is also described in this blog post.

    -Karel

    Monday, March 26, 2012 3:56 PM
    Moderator

All replies

  • Hi Frederic,

    Welcome to the MSDN Forum.

    Here is more about this flag: http://msdn.microsoft.com/en-us/library/microsoft.build.tasks.managedcompiler.prefer32bit(v=vs.110).aspx 

    This API supports the .NET Framework infrastructure and is not intended to be used directly from your code. 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 26, 2012 7:24 AM
    Moderator
  • Prefer32Bit flavour was introduced to allow applications target all 32-bit platforms (incl. ARM). It will run on x86, on ARM and on amd64 (in WOW64).
    The information is stored PE file header (as flag COMIMAGE_FLAGS_32BITPREFERRED - see corhdr.h) and can be change/viewed by corflags.ex tool as you discovered.

    Before this new flavour/flag was introduced you had only options x86Only = COMIMAGE_FLAGS_32BITREQUIRED (which would run on x86 and on amd64 [in WOW64], but not run on ARM), or AnyCPU (which would run on x86, on am64 [as 64-bit process] and also run on ARM).
    As you can see the combination of Prefer32Bit could not be achieved without this new flag.

    The flag is also described in this blog post.

    -Karel

    Monday, March 26, 2012 3:56 PM
    Moderator
  • Thanks !

    From my understanding, it's still recommended  to set the application executable to run on x86 as soon as we are not targetting ARM devices -i.e. we are still a 'pure' desktop application : when targetting ARM, our application will be different and our libraries assemblies are already with anyCPU so there is no problem.


    Monday, March 26, 2012 11:26 PM