Avatar of jjsather

asked on 

Detect if DLL Reference is Valid on Client Machine

When my exe is on a client machine, I want to see if a reference in the program is valid. Mine happens to be for SMO, but it could be anything. In my project, I've added the necessary dll references. My code is follows...

Imports Microsoft.SqlServer.Management.Smo

Private Function DoesSMOExist() As Boolean
        Dim oServer As New Server() ' See if SMO dlls are even present on the machine.
        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

Open in new window

I want my Try-Catch to return true or false, based on if a new object to this particular reference can be created. Instead, I get an unhandled exception that pops up a message, which I definitely want to avoid showing the users. The text is as follows...

System.IO.FileNotFoundException: Could not load file or assembly Microsoft.SqlServer.Smo, Version

Anyway, I don't need this to only work for this particular reference/object, but I want to know how to do it for *any* reference/object to determine if a client machine can handle it. I don't want to put the dlls on the client machine, nor do I want to search the registry (could be multiple places), nor do I want to see if a certain dll is in a certain location (could be multiple places).

I only want to detect if a given machine can reference (and create) a given DLL reference without popping up an ugly message.

Anyone know how to do it? Or can't it be done?
Visual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon