By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,602 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,602 IT Pros & Developers. It's quick & easy.

Fully Qualified Class Name via Reflection - Namespace.Namspace.ClassName

P: n/a
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!
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Nevermind, I found a workaround. I added the following function and reworked
the GetAssembly() function to instantiate the return value.

Private Function AssemblyHasType(ByRef Assem As Reflection.Assembly,
ByVal ForeignTable As String) As String
Dim x As Type

For Each x In Assem.GetTypes
If x.Name = ForeignTable Then
Return x.FullName
End If
Next

Return ""
End Function

"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
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!

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.