Type.GetType does not work in VB.NET compared to C#

enggr

New member
Joined
May 23, 2008
Messages
1
Programming Experience
5-10
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
 
Try:

Dim typ as Type = System.Type.GetType("System.String")


Does it work? If yes, then it might be that the type youre trying to retrieve isnt loaded or applicable/findable in the scope youre trying to retrieve it in. Are you able to create an instance of the class immediately after the type:

VB.NET:
Dim oType As Type = Type.GetType("JEB.DocumentIdsCaseNumbers") 
Dim x as New JEB.DocumentIdsCaseNumbers

Or does it complain it cant find the class?
 
Type.GetType("short.form") only works for mscorlib types and types of current assembly, it wouldn't surprise me if there was different behaviour for "web sites" and "web applications" that have different compilation models. The full AssemblyQualifiedName string should work. Also adding ",App_Code" as assembly indication may work for you. ("JEB.DocumentIdsCaseNumbers,App_Code")
 
Back
Top