J
Jeff Molby
Sorry for the crossposting guys. I figured this one might be a little
tricky, so I'm calling upon the C# brains out there to help out this poor VB
developer. I know enough C# to translate any code you can offer, if
necessary.
I have a very loosely coupled WinForms app written in VB.Net, Framework v1.1
I need to take a string value which contains the unqualified name of a
class, find the assembly that contains such a class, and instantiate the
class.
Here is my code to find the correct assembly.
Private Function GetAssembly(ByVal ForeignTable As String) As
Reflection.Assembly
Dim Assems() As Reflection.Assembly
Dim intLCV As Integer
Assems = AppDomain.CurrentDomain.GetAssemblies
For intLCV = 0 To Assems.Length - 1
If Not Assems(intLCV).GetType(ForeignTable, False, True) Is Nothing
Then
Return Assems(intLCV)
End If
Next
Return Nothing
End Function
It works fine, except my IF statement always returns Nothing because the
ForeignTable value is unqualified. If I hardcode it to
"BookWorks.InventoryBO.InventoryItems", it works just fine, but it fails on
"InventoryItems". It appears that I need find the namespace that covers the
assembly and concatenate that to ForeignTable. I can't find any
documentation on how to do this.
Any ideas?
Thanks everyone!
tricky, so I'm calling upon the C# brains out there to help out this poor VB
developer. I know enough C# to translate any code you can offer, if
necessary.
I have a very loosely coupled WinForms app written in VB.Net, Framework v1.1
I need to take a string value which contains the unqualified name of a
class, find the assembly that contains such a class, and instantiate the
class.
Here is my code to find the correct assembly.
Private Function GetAssembly(ByVal ForeignTable As String) As
Reflection.Assembly
Dim Assems() As Reflection.Assembly
Dim intLCV As Integer
Assems = AppDomain.CurrentDomain.GetAssemblies
For intLCV = 0 To Assems.Length - 1
If Not Assems(intLCV).GetType(ForeignTable, False, True) Is Nothing
Then
Return Assems(intLCV)
End If
Next
Return Nothing
End Function
It works fine, except my IF statement always returns Nothing because the
ForeignTable value is unqualified. If I hardcode it to
"BookWorks.InventoryBO.InventoryItems", it works just fine, but it fails on
"InventoryItems". It appears that I need find the namespace that covers the
assembly and concatenate that to ForeignTable. I can't find any
documentation on how to do this.
Any ideas?
Thanks everyone!