Avatar of Dmitry_Bond
Dmitry_Bond
Flag for Ukraine asked on

.NET - how to find type by name?

Hi.

I need an ability to find type by name.
At the moment I'm using following code:

Type t = Type.GetType("System.Data.DataTable", false, true);

but it always returns null! :-(
Why?!

The application which is run this code has a reference to System.Data.dll, so I assume it must be able to find a "System.Data.DataTable".
Any ideas?
.NET Programming

Avatar of undefined
Last Comment
Dmitry_Bond

8/22/2022 - Mon
SOLUTION
markmiddlemist

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jacques Bourgeois (James Burger)

If you already have a DataTable, you can call GetType directly on your object. Otherwise, you can instantiate a new object in order to retrieve the type:

System.Data.DataTable tb = new System.Data.DataTable;
Type t = tb.GetType();

Otherwise, you need to know the name and path of the assembly (name of the dll) that contains the type to be able to retrieve the type information.
ASKER CERTIFIED SOLUTION
Dmitry_Bond

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dmitry_Bond

ASKER
Nobody of commenters suggested a solution. Only markmiddlemist posted a useful link explaining why GetType does not work as I need it.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy