views:

56

answers:

1

I want to call managed code if and only if the currently executing assembly references it and has a match for that function name.

I have a function

Public Function TestReadableProperties() As String

    ' Not sure where to go with this line
    ' Dim names = Reflection.Assembly.GetExecutingAssembly.GetReferencedAssemblies()


    Return bLib.bReflection.GetAllReadableProperties(Me)
End Function

if the bLib.dll is not present, then I don't want the project using this DLL to complain or crash. I'd like to not have warnings about conflicting versions of dependent assemblies. This code is nice to have for testing, but I'd like to remove the dependency on this library without removing functionality if the dependencies happen to match up.

Is this possible?

A: 

Simple put your function call between a try and catch statement.

Public Function TestReadableProperties() As String
    Try
        Return bLib.bReflection.GetAllReadableProperties(Me)
    Catch
        ''// bLib is not available, let's return nothing
        Return Nothing
    End Try
End Function

Sorry for the funky comment, it's just to trick the highlighter to actually see it as a comment.

Andrew Moore
is there a more specific catch that should/could be used?
Maslow
Sure, unfortunately I don't know exactly which one it is. Try catching e As Exception and then doing a MessageBox.Show(ex.ToString, ex.GetType.ToString) to get the exact type you want to catch.
Andrew Moore