【发布时间】:2014-05-28 13:45:34
【问题描述】:
在未安装正确 .NET Framework 的情况下尝试在 Windows XP 安装上启动 C#/.NET 应用程序时,应用程序会崩溃并显示以下消息:
---------------------------
ThisApp.exe - Application Error
---------------------------
The application failed to initialize properly (0xc0000135).
Click on OK to terminate the application.
---------------------------
OK
---------------------------
老实说,这对 Joe 用户来说毫无意义,尤其是因为错误代码可能指的是不存在的 .NET Framework 以外的东西。
是否有可能以更有意义的消息崩溃? (类似“此应用程序需要 .NET Framework 3.0 才能运行。请在http://www.example.com/ 下载”)
编辑:
好的,我做了一些进一步的测试,发现了一些非常有趣的东西。
在干净的 Windows XP SP3 安装(未安装 .NET Framework)上,应用程序将始终崩溃并显示上述消息,无论它是什么 .NET Framework 版本目标,除了 .NET 4.5 和 .NET 4.5.1,它们会显示更糟糕的消息:
---------------------------
path\to\ThisApp.exe
---------------------------
path\to\ThisApp.exe is not a valid Win32 application.
---------------------------
OK
---------------------------
现在 Windows Vista 的有趣之处在于它们实际上在启动应用程序时会考虑 ThisApp.exe.config 文件。
在干净的 Windows Vista SP2 安装上(默认安装 .NET 3.5),目标是 .NET 4.0 及更高版本带有 .exe.config 导致出现以下消息:
---------------------------
ThisApp.exe - .NET Framework Initialization Error
---------------------------
To run this application, you first must install one of the following versions of the .NET Framework:
v4.0
Contact your application publisher for instructions about obtaining the appropriate version of the .NET Framework.
---------------------------
OK
---------------------------
现在没有 .exe.config,改为显示:
---------------------------
ThisApp.exe - .NET Framework Initialization Error
---------------------------
To run this application, you first must install one of the following versions of the .NET Framework:
v4.0.30319
Contact your application publisher for instructions about obtaining the appropriate version of the .NET Framework.
---------------------------
OK
---------------------------
我知道,这是一个非常小的变化,但我会带着这个去某个地方。有趣的是,即使针对 .NET 4.5 和 4.5.1,版本号(v4.0 或 v4.0.30319)也保持不变。
现在在干净的 Windows 7 SP1 安装(默认安装 .NET 4.0 客户端配置文件),目标是 .NET 4.0(完整)及更高版本 .exe.config 导致the message that was mentioned here 出现:
---------------------------
ThisApp.exe - .NET Framework Initialization Error
---------------------------
To run this application, you first must install one of the following versions of the .NET Framework:
.NETFramework,Version=v4.0
Would you like to download and install .NETFramework,Version=v4.0 now?
---------------------------
Yes No
---------------------------
现在这条消息更像它了。当分别针对 .NET 4.5 和 4.5.1 时,版本也会更改为 v4.5 和 v4.5.1。
但是,如果没有 .exe.config,应用程序会正常启动,即使针对 .NET 4.0(完整版)和更高版本(甚至 4.5)也是如此。我想如果我真的使用 .NET 4.0 full 或 4.5 及更高版本的任何功能,应用程序最终会崩溃,但我仍然认为这很有趣。假设您可以在应用程序本身中检查 .NET 的正确版本。
我无法在 Windows 8/8.1 上进行测试,但我想它与 Windows 7 相同。
不管怎样,这不是一个已解决的问题,至少在 Windows XP 上不是这样,它仍然拥有庞大的安装基础。
另外,请停止告诉我使用安装程序。我知道。这不是这个问题的目的。
【问题讨论】:
-
您的安装人员不应该这样做吗?
-
您可以/应该使用检查 .NET 并在缺失时安装它的设置来安装您的应用程序。
-
如果您不使用安装程序(您应该),那么也许使用针对较低框架版本的引导程序应用程序并让它测试较高的框架版本,如果存在,启动实际应用程序?
-
这是一个solved problem。您唯一可能犯的错误就是忽略过去 4 年的 .NET 改进。
-
@HansPassant 有趣。我做了一些测试并更新了我的问题。不幸的是,对于 Windows XP,这仍然不是一个已解决的问题。
标签: c# .net windows windows-xp