Если я правильно понимаю, вы хотите загрузить классы из сборки, не ссылаясь на проект сборки?
Тогда вы можете использовать этот класс для получения всех типов, которые реализуют / наследуют определенный тип:
Imports System.IO
Imports System.Threading
Imports Exceptions
Imports System.Reflection
Imports ModuleInterfaces
Public Class StartupLoader
Private ReadOnly syncroot As New Object
Private _handler As ExceptionHandler ' custom class to handle exceptions'
Private _typeToLoad As Type
Public Sub New(ByVal typeToLoad As Type, _
ByVal handler As ExceptionHandler)
_handler = handler
_typeToLoad = typeToLoad
End Sub
Public Function LoadDLLs() As List(Of Type)
Dim threads As New List(Of Thread)
Dim types As New List(Of Type)
Dim exceptions As New List(Of Exception)
Dim folders As New Stack(Of String)
Dim t As Thread
folders.Push(Directory.GetCurrentDirectory) ' change to your dir here, could use a member var'
While Not folders.Count = 0
For Each f In Directory.GetFiles(folders.Peek)
Dim tmp As String = f
If tmp.ToLower.EndsWith(".dll") OrElse _
tmp.ToLower.EndsWith(".exe") Then
t = New Thread(AddressOf LoadDLLsThread)
t.Start(New Object() {tmp, types, exceptions})
threads.Add(t)
End If
Next
For Each d In Directory.GetDirectories(folders.Peek)
folders.Push(d)
Next
folders.Pop()
End While
For Each t In threads
t.Join()
Next
If exceptions.Count > 0 Then
Throw New ThreadedException(exceptions) ' Custom exception containing a List(Of Exception)'
End If
Return types
End Function
Private Sub LoadDLLsThread(ByVal vObj As Object)
Dim objs As Object() = CType(vObj, Object())
Dim fileName As String = CStr(objs(0))
Dim globalTypes As List(Of Type) = CType(objs(1), Global.System.Collections.Generic.List(Of Global.System.Type))
Dim exceptions As List(Of Exception) = CType(objs(2), Global.System.Collections.Generic.List(Of Global.System.Exception))
Dim types As New List(Of Type)
Try
Dim myAssembly As Assembly = Assembly.LoadFrom(fileName)
For Each t In myAssembly.GetTypes()
If _typeToLoad.IsAssignableFrom(t) AndAlso _
t.IsClass = True AndAlso _
t.IsAbstract = False Then
types.Add(t)
End If
Next
SyncLock syncroot
globalTypes.AddRange(types)
End SyncLock
Catch ex As Exception
SyncLock syncroot
exceptions.Add(ex)
End SyncLock
End Try
End Sub
End Class
После этого используйте ответ Джона Сибли для создания объекта любого типа на лету
Ура!