Catch DllNotFoundException not working with Phidget API

197 Views Asked by At

I need to reference a dll to instantiate an object. There are cases where the dll will not exist because the Phidget drivers are not installed on those systems. In those cases I just want to catch the DllNotFoundException, but it's not working. I even tried nesting catch statements between the type reference and the instantiation, but still not catching. Any help would be appreciated.

enter image description here

1

There are 1 best solutions below

0
Ben Voigt On

I think you are seeing a problem very similar to Why does short-circuiting not prevent MissingMethodException related to unreachable branch of logical AND (&&)?

Put the catch in a separate function, one that does not use typeof(Phidget22.DigitalInput) or any other identifier from the DLL.

Exceptions such as TypeLoadException, MissingMethodException, and DllNoFoundException can be called by the JIT compiler before execution of your function starts (and then catch blocks in the function will have no effect).