缺少 .dll 时如何防止应用程序崩溃?

How to prevent application from crashing when .dll is missing?

我希望我的程序在丢失 .dll 文件的情况下通知用户这一事实,而不是仅仅因 FileNotFoundException 引用此 .dll.

而崩溃

此库已通过引用包含到项目中。

甚至在我的任何代码执行之前就抛出了异常,所以我无法处理 它。

你只有 2 个选项(据我所知)

  • 你需要动态加载dll,反映你的需要
  • 编写加载器应用程序以在启动应用程序之前检查 dll

这个问题可能会让您开始选择选项一

Loading DLLs at runtime in C#

However : i guess its just easier to make sure they have the dll or include it in the build

在应用程序启动期间,您可以为任何未处理的异常注册应用程序域:

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

您的处理程序应负责向用户显示适当的消息。