My application contains links to an external library (SQL Server management objects). Apparently, if the library is not in the runtime system, the application still works until methods that use classes from this library are called.
Question 1: Is this a given behavior or just a (successful) side effect of how the CLR loads libraries?
To determine if this link is available, I am currently using the following code:
Function IsLibraryAvailable() As Boolean Try TestMethod() Catch ex As FileNotFoundException Return False End Try Return True End Function Sub TestMethod() Dim srv As New Smo.Server() ' Try to create an object in the library End Sub
It works, but it seems pretty ugly. Note that it only works if TestMethod is a separate method, otherwise an exception will be thrown at the beginning of IsLibraryAvailable (before try-catch, even if an object instance occurs in the try-catch block).
Question 2: Is there a better alternative?
In particular, I'm afraid that optimizations like the inlining function might stop my code.
source share