如何在 64 位环境中运行 32 位 .NET 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1108137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run a 32-bit .NET application in a 64-bit environment?
提问by Fredrik Leijon
We developed a C# application using the .NET Framework 2.0 which works fine in 32-bit computers. But when I run my application in a 64-bit environment, it crashes.
我们使用 .NET Framework 2.0 开发了一个 C# 应用程序,它在 32 位计算机上运行良好。但是当我在 64 位环境中运行我的应用程序时,它崩溃了。
I need to make my application to run in 64-bit environment.
我需要让我的应用程序在 64 位环境中运行。
How do I do this?
我该怎么做呢?
回答by Fredrik Leijon
You could compile it for x86 instead of any cpu that way it will run against 32bit librarys on a 64bit windows.
您可以为 x86 而不是任何 cpu 编译它,这样它将在 64 位 Windows 上针对 32 位库运行。
Or swap 32bit librarys for 64bit when installning on 64bit windows. Among other some Sqlite dlls are specific for 32/64 bit
或者在 64 位 Windows 上安装时将 32 位库交换为 64 位。在其他一些 Sqlite dll 中,特定于 32/64 位
回答by Libor
If you are on Windows you shall use CorFlagsConversion Tool (CorFlags.exe). This way you might enforce application/dll's to run in 32/64 bit space. Details and examples of use are available at http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx.
如果您使用的是 Windows,则应使用CorFlags转换工具 ( CorFlags.exe)。这样您就可以强制应用程序/dll 在 32/64 位空间中运行。详细信息和使用示例可在http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx 上找到。
回答by Robb
Here is what looks to be a nice solution if you are looking to avoid recompilation. Note it does require a change to each target machine.
如果您希望避免重新编译,这看起来是一个不错的解决方案。请注意,它确实需要对每台目标机器进行更改。
If you have a 64 bit machine and want to run a .NET application that only works with the 32 bit CLR you would have to make changes to the .NET framework on your machine
Set the .NET framework to load the CLR in WOW mode through this command
Open up command prompt and type this command
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe SetWow
Now you should be able to run apps that use only the .NET 32 bit CLR.
To revert back to the default 64 bit framework run
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe Set64
如果您有一台 64 位机器并且想要运行一个仅适用于 32 位 CLR 的 .NET 应用程序,您将必须对您机器上的 .NET 框架进行更改
通过这个命令设置.NET框架在WOW模式下加载CLR
打开命令提示符并键入此命令
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe SetWow
现在您应该能够运行仅使用 .NET 32 位 CLR 的应用程序。
恢复到默认的 64 位框架运行
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe Set64
(source)
(来源)
回答by Martin Liversage
In the build settings for you project set the platform target to x86 instead of Any CPU. This will solve problems where your project has "hidden" dependendencies on 32 bit subsystems that are not available in 64 bit. Your application will then run in the 32 bit susbsystem on 64 bit Windows.
在您项目的构建设置中,将平台目标设置为 x86 而不是任何 CPU。这将解决您的项目对 32 位子系统具有“隐藏”依赖关系而在 64 位系统中不可用的问题。然后,您的应用程序将在 64 位 Windows 上的 32 位子系统中运行。
回答by Steven de Salas
Just expanding on Fredrik Leijon's answer above, I think this is what you are after.
只是扩展上面 Fredrik Leijon 的回答,我认为这就是你所追求的。
It will tell both 64 and 32 bit windows to run your application on the 32 bit environment.
它将告诉 64 位和 32 位窗口在 32 位环境中运行您的应用程序。
Remeber to do the same for your 'Release' configuration.
请记住对您的“发布”配置执行相同的操作。


This will in turn update your *.csproj file for MSBuild to pick up as follows (check the <PlatformTarget/>element below):
这将依次更新您的 *.csproj 文件,以便 MSBuild 选择如下(检查<PlatformTarget/>下面的元素):
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
回答by Jehof
I faced the same problem. I my case it was enough to compile the main assembly (.exe) of my application especially for "x86". The other assemblies (.dll) are compiled with "Any CPU".
我遇到了同样的问题。我的情况是编译我的应用程序的主程序集(.exe)就足够了,特别是对于“x86”。其他程序集 (.dll) 使用“任何 CPU”编译。
Our application then works fine on 32Bit and 64Bit systems.
然后我们的应用程序可以在 32Bit 和 64Bit 系统上正常工作。
回答by rein
It should just run unless you're referencing libraries that are specifically only available for 32bit (Jet DB drivers are one example) or unless you've told your compiler to compile your application to 32bit only.
它应该只运行,除非您引用专门仅适用于 32 位的库(Jet DB 驱动程序就是一个示例),或者除非您告诉编译器将应用程序编译为仅 32 位。
What does the crash say?
车祸说明了什么?
回答by rein
Is it Windows/ASP.NET application?
它是 Windows/ASP.NET 应用程序吗?
If it is an ASP.NET application. you can run only 32/64-bit modes at the same time. For doing this,
如果是 ASP.NET 应用程序。您只能同时运行 32/64 位模式。为了做到这一点,
Case 1. you need to Enable32bitApplicationon the application pool in the IIS.
Then reset the IIS.
案例1.你需要Enable32bitApplication在IIS上的应用程序池。然后重置IIS。
Case 2. Check for the corresponding DLL in regedit.
案例2.在regedit中检查对应的DLL。
If it is windows based, run this command from Visual Studio prompt,
如果它是基于 Windows 的,请从 Visual Studio 提示符运行此命令,
CorFlags.exe TheApp.exe /32BIT+ //Enables 32 bit application.

