为什么我的 WinForms 应用程序不能为“x86”编译? 在“x64”上退出 机器在“C:\Program Files (x86)”之外运行时?

发布于 2024-07-17 18:51:17 字数 380 浏览 4 评论 0原文

我们有一个 WinForms 应用程序,可以在 x86 上正常运行,但有许多进行 win32 调用的第三方组件。 为了让应用程序在 x64 上运行,我现在针对 x86 平台进行编译。 我们的习惯是将胖客户端安装在服务器系统分区之外,因此我们昨天在 Win2003 x64 服务器上安装在“F:\Program Files (x86)”中。 当从该目录运行时,进程拒绝退出。 我尝试在任务管理器、taskkill 和 Process Explorer 中杀死它们,但除了重新启动服务器之外,没有什么办法可以杀死这些进程。 当我在 C:\Program Files (x86) 中卸载并重新安装时,进程正常退出。

在 x64 计算机上运行为 x86 编译的 WinForms 应用程序时,安装位置真的很重要吗?

We have a WinForms app that runs fine on x86, but has many third-party components that make win32 calls. To get the apps to run on x64, I now compile for the x86 platform. Our habit has been to install our thick-client outside the system partition on servers, so we installed in "F:\Program Files (x86)" yesterday on a Win2003 x64 server. When run from that directory, the processes refused to exit. I tried killing them in Task Manager, taskkill, and Process Explorer, but nothing short of rebooting the server would kill those processes. When I uninstalled and reinstalled in C:\Program Files (x86), the processes exit fine.

Does the installation location really matter when running WinForms apps compiled for x86 on an x64 machine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌酱 2024-07-24 18:51:17

根据我的经验,我可以说几乎可以从任何位置在 x64 系统上运行 x86 二进制文件(尚未测试如果二进制文件位于 system32 中是否仍然有效,但我确信 x86 程序可以从 Program Files 运行)。 我相信 Program Files / Program Files (x86) 文件夹只是为了轻松区分本机 x64 应用程序和旧的 x86 应用程序。 从您的描述来看,您面临的问题听起来很像 WoW64 兼容性问题,但是,如果您依赖于非托管代码,您可能需要首先验证该非托管代码是否运行良好,然后深入了解阻止您的程序的原因关闭。 此外,了解您首先如何尝试终止应用程序、它使用多线程还是单线程、目标 .NET 运行时的版本以及服务器上安装的版本(包括。 服务包)。

From my experience I can tell that it is possible to run x86 binaries on x64 systems from pretty much any location (haven't tested if things still work if the binary is in system32, but I'm sure x86 programs can run from Program Files). I believe the Program Files / Program Files (x86) folders are just there to easily distinguish between native x64 apps and old x86 apps. From your description what you're facing sounds much like a WoW64 compatibility issue, however if you've got dependencies on unmanaged code you'll probably want to verify first if that unmanaged code runs fine and then dig deeper in what's preventing your program from closing. Also, it would be helpful to know how are you trying to terminate the application in the first place, if it uses multiple threads or a single thread, the version of the .NET runtime that's targeting and the version that's installed on the server (incl. Service Pack).

梓梦 2024-07-24 18:51:17

这是在黑暗中拍摄的。 您的程序是否尝试读取或加载与应用程序一起部署在同一目录或子目录中的任何数据? 如果是这样,您可能会遇到以下问题。

您的应用程序可能使用依赖于其运行所在的处理器体系结构的值来查找目录。 以环境变量 ProgramFiles 为例。 在 64 位计算机上,ProgramFiles 环境变量实际上指向 32 位应用程序的“Program Files (x86)”目录。 因此,您的程序可能正在尝试加载如下所示的数据并崩溃

string root = Environment.GetVariable("ProgramFiles");
string file = Path.Combine(root, "MyAppName\DataDirectory\SomeDataFile.txt");
string data = File.ReadAllLines(file);  

最后一行将失败,因为路径将解析为

c:\program files (x86)\MyApplication\DataDirectory\SomeDataFile.txt

但应用程序已部署到 Program Files 中。 所以真正的路径是

c:\program files\MyApplication\DataDirectory\SomeDataFile.txt

Here's a shot in the dark. Does your program attempt to read or load any data that is deployed with the application in the same directory or a sub directory? If so, there's the possibility that you are running into the following problem.

It's possible that your application is using a value that is dependent on the processor architecture that it is running under to find the directory. Take for instance the environment variable ProgramFiles. On a 64 bit machine, the ProgramFiles environment variable will actually point to the "Program Files (x86)" directory for a 32 bit application. So it's possible you're program is attempting to load data like the following and crashing

string root = Environment.GetVariable("ProgramFiles");
string file = Path.Combine(root, "MyAppName\DataDirectory\SomeDataFile.txt");
string data = File.ReadAllLines(file);  

The last line would fail because the path would resolve to

c:\program files (x86)\MyApplication\DataDirectory\SomeDataFile.txt

But the application was deployed into Program Files. So the real path would be

c:\program files\MyApplication\DataDirectory\SomeDataFile.txt

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文