我需要引用一个dll来实例化一个对象。有些情况下,由于这些系统上没有安装Phidget驱动程序,因此dll将不存在。在那些情况下我只想抓住 DllNotFoundException ,但不起作用。我甚至尝试在类型引用和实例化之间嵌套catch语句,但仍然没有捕获。任何帮助都将不胜感激。
DllNotFoundException
我想你看到的问题和 Why does short-circuiting not prevent MissingMethodException related to unreachable branch of logical AND (&&)?
typeof(Phidget22.DigitalInput) 或DLL中的任何其他标识符。
typeof(Phidget22.DigitalInput)
例外情况,如 TypeLoadException , MissingMethodException DllNoFoundException 可以在开始执行函数之前由JIT编译器调用(然后函数中的catch块将不起作用)。
TypeLoadException
MissingMethodException
DllNoFoundException