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
Type type_ClassName = Type.GetType(className); //Works like a charm
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
have a look on this article http://ziqbalbh.wordpress.com/2008/05/27/typegettype/
** Please mark as ANSWER if my reply helped you
Could you use the TypeOf Operator as all??
Dim ty As Boolean = TypeOf <object> Is JEB.DocumentIdsCaseNumbers
I know this example is not exact but it may help you??
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.
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB
Dim Form1 As Form = Activator.CreateInstance(Of frmContractEdit)()
Dim Form2Type As Type = GetType(frmContractEdit)
Dim Form2 As Form = CType(Activator.CreateInstance(Form2Type), Form)
'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)
Dim Form3 As Form = CType(Activator.CreateInstance(Form3Type), Form)
Dim Form4 As Form = CType(Activator.CreateInstance(Type.GetType("Fusion.frmContractEdit", True, True)), Form)