Asked by:
Type.GetType does not work in VB.NET but works in C#. VB.NET gurus Please help

Question
-
User-716244244 posted
Friends,
I am an experienced C# programmer who is working on a VB.NET project now. I am writing different methods covering the following functionalities
1) Take a datareader as input and return an arraylist of class object
2) Take an xmlnode (received from a webservice) as input and return an arraylist of class object.
The methods are generic methods which take datareader/xmlnode as first parameter and classname (string) as the second parameter. This way it will work trivially.
The schema of class object matches with the input (datareader or xmlnode)
In C# I used to do this by using reflection and Type.GetType(). But the Type.GetType() is not working in VB.NET. Its returning "Nothing". I made sure that the namespace/class names are spelled properly. I even tested the same code in C# and it works like a charm. Only in VB.net it does not work.
The .vb file is created inside the App_Code folder of the web application.
I read other posts and removed the temporary asp.net files and stuff but didn't help
Any help will be greatly appreciated
C# code
Type type_ClassName = Type.GetType(className); //Works like a charm
VB.NET code
Dim oType As Type = Type.GetType("JEB.DocumentIdsCaseNumbers") // Does not work [:(]
I used Immediate window on debug mode for both vb.net and c# and confirmed that it does not work in vb.net
Please help me to get the GetType() working in VB.NET
Friday, May 23, 2008 2:32 PM
All replies
-
User-168033412 posted
Hi,
have a look on this article http://ziqbalbh.wordpress.com/2008/05/27/typegettype/
Tuesday, May 27, 2008 6:42 AM -
User-1899898566 posted
Hi,
Could you use the TypeOf Operator as all??
Dim ty As Boolean = TypeOf <object> Is JEB.DocumentIdsCaseNumbersI know this example is not exact but it may help you??
Regards
Nick
Friday, May 30, 2008 8:56 AM -
User397347636 posted
Type.GetType is a framework call - it should work identically in C# and VB.
The global VB GetType macro is another story (and is equivalent to the C# 'typeof' operator), but this isn't a factor here.
Friday, May 30, 2008 10:33 AM -
User1837512635 posted
'Method 1
Dim Form1 As Form = Activator.CreateInstance(Of frmContractEdit)()
Form1.Show()
'Method 2
Dim Form2Type As Type = GetType(frmContractEdit)
MsgBox(Form2Type.AssemblyQualifiedName)
Dim Form2 As Form = CType(Activator.CreateInstance(Form2Type), Form)
Form2.Show()
'Method 3
'Fusion. needs to be in front and was found using MsgBox above
'frmContractEdit needs to have Inherits System.Windows.Forms.Form in its Class definition (designer)
Dim Form3Type As Type = Type.GetType("Fusion.frmContractEdit", True, True)
MsgBox(Form3Type.AssemblyQualifiedName)
Dim Form3 As Form = CType(Activator.CreateInstance(Form3Type), Form)
Form3.Show()
'Method 4
Dim Form4 As Form = CType(Activator.CreateInstance(Type.GetType("Fusion.frmContractEdit", True, True)), Form)
Form4.Show()
Monday, October 6, 2008 8:16 PM