c# - 更好地处理丢失的 .NET Framework (0xc0000135) 崩溃?

标签 c# .net windows windows-xp

当尝试在未安装正确 .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 Client Profile),针对 .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 完整版或 4.5 及更高版本的任何功能,该应用程序最终会崩溃,但我仍然认为它非常有趣。假设地,您将能够检查应用本身内的 .NET 版本是否正确。

我无法在 Windows 8/8.1 上进行测试,但我想它与 Windows 7 相同。

无论哪种方式,这都不是一个已解决的问题,至少在仍然拥有大量安装基础的 Windows XP 上是这样。

此外,请停止告诉我使用安装程序。我知道。这不是这个问题的目的。

最佳答案

Which is honestly pretty meaningless to a Joe User,

只有 Joe 用户应该启动已安装的程序。安装程序有责任处理先决条件。

Is it somehow possible to crash with a more meaningful message?

不,因为你不会崩溃。不在 .NET 中。创建 .NET 时,微软使文件向后兼容。它是可执行文件中的 native 初始化代码,而不是 .NET 代码中的代码。没有运行时,.NET 代码无法运行。

有趣的是,这是一个已解决的问题。您使用的是完全过时的 .NET 版本,因为这个问题已在最新版本(.NET 4.0 以上)中得到修复,并带有一个更有意义的对话框。

http://blogs.msdn.com/b/dotnet/archive/2012/03/07/optimizing-the-net-framework-deployment-experience-for-users-and-developers.aspx

有引用。取决于直接导致下载/安装对话框的 Windows 版本。

.NET 3.0 相当古老。

关于c# - 更好地处理丢失的 .NET Framework (0xc0000135) 崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23062809/

相关文章:

.net - Rx ForkJoin 丢失

c++ - 如何诊断 Windows 上的堆损坏错误?

windows - 批处理文件中的通配符

c# - DataGridView 在 Visual Studio 2019 ToolBox 上不可用

c# - 对象没有出现在 Hololens 中 Vuforia 标记的顶部/中心,如何解决?

c# - 为 Web 服务生成动态 XML 的最佳方法是什么?

c# - 指定的强制类型转换无效 – SQL float to C# double

windows - 在 Visual Basic 6 中访问动态加载的 DLL(使用 LoadLibrary)

c# - BotFramework - 使用 Json 模式定义表单 - 如何访问 OnCompletion 方法中的表单字段?

c# - C# 16 位字符如何编码所有 Unicode 字符?