LoadAssembly - Loading an assembly identified by the path or the partial name
' Load an assembly identified by the path or the partial name
' Note: requires Imports System.Reflection
'
' Examples:
' 1) Dim asm As [Assembly] = LoadAssembly("System.Web")
' 2) Dim asm As [Assembly] = LoadAssembly("C:\MyApp\MyAssembly.dll")
Function LoadAssembly(ByVal asmFile As String) As [Assembly]
Dim asm As [Assembly]
Try
' attempt to load the assembly from a path
asm = [Assembly].LoadFile(asmFile)
Catch ex As Exception ' ignore exceptions
End Try
Try
' attempt to load an assembly with this (partial) name
If asm Is Nothing Then
asm = [Assembly].LoadWithPartialName(asmFile)
End If
Catch ex As Exception ' ignore exceptions
End Try
' return whatever we have found so far
Return asm
End Function