Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
| Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 23rd, 2008, 01:37 PM
Registered User
 
Join Date: Dec 2006
Location: Los Angeles, CA, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Type.GetType does not work in VB.NET. Please help

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




  #2 (permalink)  
Old May 24th, 2008, 04:03 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You probably want to use VB's GetType directly like this:

Dim type_ClassName As Type = GetType(ClassName)

Alternatively, if you need to check whether an instance is of a certain type you can also use TypeOf:

If TypeOf (instance) Is ClassName Then
 ...
End If

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old June 3rd, 2008, 06:07 AM
Registered User
 
Join Date: Jun 2008
Location: liverpool, , United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had a similar problem and Type.GetType( [string] ) was not working.

Check if you have already declared a class with the name Type. You can inevertently do this by creating LINQ classes. If this is the case then you will need to type.

System.Type, as the following example shows:

Dim typeModificator As System.Type = System.Type.GetType(("TemplateParser.Modificators. " + strExtra))

Hope this helps anyone stumbling across it.


There's plenty of different ways to skin a cat.


Similar Threads
Thread Thread Starter Forum Replies Last Post
default(System.Type) does this exist in VB.NET 2k5 Peace2u ASP.NET 2.0 Basics 0 August 18th, 2006 06:51 AM
Dowloaded code (VB.NET 2003) does not work kadesskade VB.NET 2002/2003 Basics 2 July 10th, 2006 12:49 AM
what data type in vb.net holds more thab 256 bits Hisham VB.NET 2002/2003 Basics 1 November 8th, 2004 05:35 AM
How to work on a VB.NET project from 2 PC's crt VS.NET 2002/2003 3 June 17th, 2003 10:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.