I've built a Windows service as "Any CPU". However, when I run it on my 64 bit machine it runs in 32 bit. How can I fix it? I'm using .NET and C#, and my operating system is Windows 2008 R2.
If I build it in x64 it correctly loads in 64 bit mode. However, "Any Cpu" -- which is what I want -- loads in 32 bit, even though the machine it's running on perfectly supports 64 bit.
EDIT to add more information based on feedback
We do have third party tools as well as reference a c++ managed assembly. These may or may not be built for any CPU. In fact i know that the c++ managed assembly is only built for x86. However, the odd things is that if I specifically specify x64 the process will start up and work in x64. If the framework were to attempt to load the c++ managed assembly it would fail. I don't mind this, because in the code, we do not load the 32bit managed ++ assembly if we're running in 64 bit mode. Could it be that the build figures that since there is a 32 bit assembly in here it should mark the launching process (in this case a windows service assembly) as x86?
You need to use the 64bit version of installutil.exe to install for 64bit. The normal 32bit version cannot do this. This was my problem.
No. You can only upgrade to another version of Windows with the same bit amount. If you wish to transition from a 32-bit version to a 64-bit version or vice versa, you would have to back up all of your files and perform a Custom installation of the version to install. Can I run 32-bit programs on a 64-bit computer?
Most computers used to be sold with 32 bit operating systems as that is normally all that is required to run common programs that most use. 32 bit OS will only access 4 GB of memory (RAM) so if your computer has 4 GB or less RAM it is almost certain that you have a 32 bit OS.
In case anybody runs across the same thing I did: I had created two new config settings (copied from the Debug config). For some reason "Prefer32Bit" flag was set to true, even though the checkbox was greyed out and unchecked in the project config page.
You can fix it by removing the line directly from the .csproj file.
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Staging|AnyCPU'"> <DebugSymbols>true</DebugSymbols> <OutputPath>bin\Staging\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <DebugType>full</DebugType> <PlatformTarget>AnyCPU</PlatformTarget> <ErrorReport>prompt</ErrorReport> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <Prefer32Bit>true</Prefer32Bit> <!-- REMOVE THIS LINE --> </PropertyGroup>
There's a setting that can force AnyCPU assemblies to run as 32-bit on x64 OS.
Use ldr64.exe from .Net2 x64 directory to check the status:
C:\Windows\Microsoft.NET\Framework64\v2.0.50727>ldr64.exe query loading kernel32...done. retrieved GetComPlusPackageInstallStatus entry point retrieved SetComPlusPackageInstallStatus entry point Current status is: 0x00000001
1 - means 'run AnyCPU as 64-bit'
0 - means 'run AnyCPU as 32-bit'
Though I didn't find such utility in .Net v4 folder, the setting applies to Net4 AnyCPU assemblies as well. This flag is saved in DWORD registry value Enable64Bit under the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
This setting seems to be loaded on OS start, and changing only registry value doesn't affect applications until reboot. Changing the flag with ldr64.exe takes effect immediately.
Note that this setting is system-wide. By default Enable64Bit is set to 1. It seems that some application reset it to 0, and reverting the value back can cause problem to that app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With