1

我需要引用一个 dll 来实例化一个对象。在某些情况下,dll 将不存在,因为这些系统上未安装 Phidg​​et 驱动程序。在这些情况下,我只想抓住DllNotFoundException,但它不起作用。我什至尝试在类型引用和实例化之间嵌套 catch 语句,但仍然没有捕捉到。任何帮助,将不胜感激。

在此处输入图像描述

4

1 回答 1

0

我认为您看到的问题非常类似于Why does short-circuiting not prevent MissingMethodException related to unreachable branch of logical AND (&&)?

将 catch 放在一个单独的函数中,该函数不使用typeof(Phidget22.DigitalInput)DLL 中的任何其他标识符。

JIT 编译器可以在函数开始执行之前调用诸如 、 和 之类的异常TypeLoadExceptionMissingMethodException然后DllNoFoundException函数中的 catch 块将不起作用)。

于 2018-06-14T22:57:13.367 回答