locked
.NET 'Any CPU' targeted Winform EXE runs as 32-bit on *some* Vista x64 computers

    Question

  • There is a very strange problem I am encountering regarding running .NET apps on a particular Vista Business x64 machine. This OS was installed on the hardware (it is not a virtual machine) about 3 months ago and has Visual Studio 2008, Office 2007 and MS SQL Server installed.

    I created a Winforms EXE in Visual Studio 2008 and targeted "Any CPU" - I expect this EXE to run as a 64-bit process in Vista x64. However when I run this program on my Vista x64 machine the program shows up as a 32-bit process.

    I also compiled this same program as targeting x64 (rather than 'Any CPU' ) and it does indeed run as a 64-bit process on the same machine.

    Examine the Process Explorer screenshot below for WindowsFormApplication1ANYCPU.exe (ANY CPU targeted) and WindowsFormApplication1x64.exe (x64-targeted).

    I verified this by examining the 32-bit/64-bit column of Process Explorer, along with observing the .NET framework DLLs which are being loaded (SysWow64 for the ANY CPU 32-bit process, System32 for the x64-targeted version)

    Now, before someone suggests the possibility of 3rd party DLLs or other dependencies causing this behavior, I should mention that this EXE is an empty new Winform EXE project created by Visual Studio 2008. So there are no possible dependencies affecting this. I also observe that .NET applications like Paint.NET end up running as 32-bit on this particular machine, when it should be running as 64-bit.

    I can take this same executable (the one targeted 'Any CPU ') and run it on another Vista x64 computer, and it runs as a 64-bit program. So it seems like there is something peculiar about my OS that is causing it to run 'ANY CPU ' .NET apps as 32-bit. Is there a setting somewhere in Windows that could be causing this? Talking to my colleagues, they have also encountered this behavior on certain computers and have worked around it by compiling x86- and x64-targeted version of their app and letting their installer install the correct version.

    Obviously this can cause serious issues if for example you are linking to a 64-bit DLL and you are expecting your code to run as 64-bit on x64, but for whatever reason it ends up running in 32-bit mode.

    The sample project I used is here (although since it is just a default Visual Studio empty project there is not much to see)

    Also, I turned on Fusion logging with  C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\FUSLOGVW.exe but saw no interesting information.

    Here is the screenshot of the behavior I am seeing:

    Friday, May 01, 2009 7:55 PM

All replies

  • Pretty strange, first time I've heard of this.  Run the Corflags.exe utility on the .exe to double-check that the 32BIT flag is indeed off.  Beware that if you change the Platform Target setting, you have to do so for both the Debug and the Release configuration.

    Hans Passant.
    Friday, May 01, 2009 8:41 PM
    Moderator
  • Yes it truly is weird.  It is a tough problem to Google also, because all you find are countless posts and articles explaining the way it is *supposed* to work.

    >> Run the Corflags.exe utility on the .exe to double-check that the 32BIT flag is indeed off
    Shown below - the first one is the 'Any CPU' version, the 2nd one is 'x64-targeted' EXE. As expected, 32-bit is '0' for both EXEs.

    Even if the 32-bit flag was turned on, that could not explain how the identical 'Any CPU' EXE runs as 64-bit on another Vista x64 computer.


    C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64>corflags "C:\temp\WindowsFormsApplication1x64\WindowsFormsApplication1x64\bin\Debug\WindowsFormsApplicatio
    n1ANYCPU.exe"
    Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  3.5.21022.8
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Version   : v2.0.50727
    CLR Header: 2.5
    PE        : PE32
    CorFlags  : 1
    ILONLY    : 1
    32BIT     : 0
    Signed    : 0

    C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64>corflags "C:\temp\WindowsFormsApplication1x64\WindowsFormsApplication1x64\bin\x64\Debug\WindowsFormsApplication1x64.exe"
    Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  3.5.21022.8
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Version   : v2.0.50727
    CLR Header: 2.5
    PE        : PE32+
    CorFlags  : 1
    ILONLY    : 1
    32BIT     : 0
    Signed    : 0

    Friday, May 01, 2009 8:53 PM
  • I dunno.  The only thing I can imagine is that the CLR decides at runtime that it shouldn't switch to 64-bit mode.  Maybe there's a 32-bit DLL loaded in the process.  Virus checkers tend to do this.  Just a guess.

    Hans Passant.
    Friday, May 01, 2009 9:49 PM
    Moderator
  • A/V - that's a great suggestion nobugz! I will try uninstalling my A/V (Symantec) and see if the behavior persists. If A/V is the cause, it would be a fairly big oopsie-daisy on Symantec's part.
    Saturday, May 02, 2009 2:14 AM
  • I uninstalled my A/V and the problem persists. I also checked if there were any modules being injected into the process but the only modules I see are normal Microsoft DLLs (below). So on goes my search to figure out why this is happening.

    Process: WindowsFormsApplication1ANYCPU.exe Pid: 4768
    
    Name	Description	Company Name	Version	Path
    l_intl.nls				C:\Windows\SysWOW64\l_intl.nls
    sorttbls.nlp				C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\sorttbls.nlp
    locale.nls				C:\Windows\System32\locale.nls
    sortkey.nlp				C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\sortkey.nlp
    locale.nls				C:\Windows\System32\locale.nls
    WindowsFormsApplication1ANYCPU.exe	WindowsFormsApplication1x64	Microsoft	1.0.0.0	C:\temp\WindowsFormsApplication1x64\WindowsFormsApplication1x64\bin\Debug\WindowsFormsApplication1ANYCPU.exe
    ntdll.dll	NT Layer DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\system32\ntdll.dll
    wow64.dll	Win32 Emulation on NT64	Microsoft Corporation	6.0.6001.18000	C:\Windows\system32\wow64.dll
    wow64win.dll	Wow64 Console and Win32 API Logging	Microsoft Corporation	6.0.6001.18000	C:\Windows\system32\wow64win.dll
    wow64cpu.dll	AMD64 Wow64 CPU 	Microsoft Corporation	6.0.6001.18000	C:\Windows\system32\wow64cpu.dll
    mscorrc.dll	Microsoft .NET Runtime resources	Microsoft Corporation	2.0.50727.3053	C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorrc.dll
    user32.dll.mui	Multi-User Windows USER API Client DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\SysWOW64\en-US\user32.dll.mui
    msctf.dll.mui	MSCTF Server DLL	Microsoft Corporation	6.0.6000.16386	C:\Windows\SysWOW64\en-US\msctf.dll.mui
    kernel32.dll.mui	Windows NT BASE API Client DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\SysWOW64\en-US\kernel32.dll.mui
    ntdll.dll	NT Layer DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\SysWOW64\ntdll.dll
    mscoree.dll	Microsoft .NET Runtime Execution Engine	Microsoft Corporation	2.0.50727.3053	C:\Windows\SysWOW64\mscoree.dll
    KERNEL32.dll	Windows NT BASE API Client DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\KERNEL32.dll
    ADVAPI32.dll	Advanced Windows 32 Base API	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\ADVAPI32.dll
    RPCRT4.dll	Remote Procedure Call Runtime	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\RPCRT4.dll
    Secur32.dll	Security Support Provider Interface	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\Secur32.dll
    SHLWAPI.dll	Shell Light-weight Utility Library	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\SHLWAPI.dll
    GDI32.dll	GDI Client DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\GDI32.dll
    USER32.dll	Multi-User Windows USER API Client DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\USER32.dll
    msvcrt.dll	Windows NT CRT DLL	Microsoft Corporation	7.0.6001.18000	C:\Windows\syswow64\msvcrt.dll
    IMM32.DLL	Multi-User Windows IMM32 API Client DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\SysWOW64\IMM32.DLL
    MSCTF.dll	MSCTF Server DLL	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\MSCTF.dll
    LPK.DLL	Language Pack	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\LPK.DLL
    USP10.dll	Uniscribe Unicode script processor	Microsoft Corporation	1.626.6001.18000	C:\Windows\syswow64\USP10.dll
    comctl32.dll	User Experience Controls Library	Microsoft Corporation	6.10.6001.18000	C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6001.18000_none_5cdbaa5a083979cc\comctl32.dll
    mscorwks.dll	Microsoft .NET Runtime Common Language Runtime - WorkStation	Microsoft Corporation	2.0.50727.3053	C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
    MSVCR80.dll	Microsoft® C Runtime Library	Microsoft Corporation	8.0.50727.3053	C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.3053_none_d08d7bba442a9b36\MSVCR80.dll
    shell32.dll	Windows Shell Common Dll	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\shell32.dll
    ole32.dll	Microsoft OLE for Windows	Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\ole32.dll
    mscorlib.ni.dll	Microsoft Common Language Runtime Class Library	Microsoft Corporation	2.0.50727.3053	C:\Windows\assembly\NativeImages_v2.0.50727_32\mscorlib\9adb89fa22fd5b4ce433b5aca7fb1b07\mscorlib.ni.dll
    uxtheme.dll	Microsoft UxTheme Library	Microsoft Corporation	6.0.6001.18000	C:\Windows\SysWOW64\uxtheme.dll
    mscorjit.dll	Microsoft .NET Runtime Just-In-Time Compiler	Microsoft Corporation	2.0.50727.3053	C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
    System.ni.dll	.NET Framework	Microsoft Corporation	2.0.50727.3053	C:\Windows\assembly\NativeImages_v2.0.50727_32\System\aa7926460a336408c8041330ad90929d\System.ni.dll
    System.Drawing.ni.dll	.NET Framework	Microsoft Corporation	2.0.50727.3053	C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Drawing\6978f2e90f13bc720d57fa6895c911e2\System.Drawing.ni.dll
    System.Windows.Forms.ni.dll	.NET Framework	Microsoft Corporation	2.0.50727.3053	C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\9a254c455892c02355ab0ab0f0727c5b\System.Windows.Forms.ni.dll
    System.Configuration.ni.dll	System.Configuration.dll	Microsoft Corporation	2.0.50727.3053	C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Configuration\cb4cb21d14767292e079366a5d3d76cd\System.Configuration.ni.dll
    System.Xml.ni.dll	.NET Framework	Microsoft Corporation	2.0.50727.3053	C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Xml\36f3953f24d4f0b767bf172331ad6f3e\System.Xml.ni.dll
    gdiplus.dll	Microsoft GDI+	Microsoft Corporation	5.2.6001.18000	C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.6001.18000_none_9e752e5ac9c619f3\gdiplus.dll
    CLBCatQ.DLL	COM+ Configuration Catalog	Microsoft Corporation	2001.12.6931.18000	C:\Windows\syswow64\CLBCatQ.DLL
    OLEAUT32.dll		Microsoft Corporation	6.0.6001.18000	C:\Windows\syswow64\OLEAUT32.dll
    
    Wednesday, May 06, 2009 3:58 PM
  • Interesting, I've no idea why the 32 bit version of mscoree.dll is loaded eventually which undoubtedly will load the 32 bit version of CLR.

    Have you tried creating a empty console application to verify if the issue remains?

    Thanks
    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Thursday, May 07, 2009 9:49 AM
  • Any news on this issue?  I too am having the problem...
    Thursday, April 08, 2010 2:52 PM
  • And I have this problem too.

    OS: Windows 2008R2

    Installes software: SQL Server 2008R2 x64 Standard, Proliant Supportpack 8.7, Adobe reader X and the .net runtime 3.5.1 and 4.0 (Client profile + Extended), No virus scanner.

    And all "Any CPU" exe's are running as 32 bit processes.

     

    On another server (Windows 2003R2 x64), the same executables run 64 bits ....

    Wednesday, June 08, 2011 10:28 AM
  • Finally got the answer from MS a while ago.  There is apparently a global flag to force 32bit processes.  THis should clear it.

    Steps:

    1.       From the command go to C:\Windows\Microsoft.NET\Framework64\v2.0.50727

    2.       Run ldr64 set64

    3.       Run the application. (Application should run as 64 bit on 64 bit machine)

     

     

    Wednesday, June 08, 2011 2:01 PM
  • Thank you, that did the trick!

     

    Wednesday, June 08, 2011 2:08 PM
  • This did the trick for me as well! Thanks!

    Thursday, June 16, 2011 1:12 PM