Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,


I am making a bll class. and trying to create a instance object with Type.GetType. My string is :
HTML
V2.PaidBLL.Reports.ReportRequests, V2.PaidBLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
it comes in str.
code is:
C#
Type t = Type.GetType(str);
but it is not not working.

Thanks
Kuldeep Dwivedi
Posted
Updated 16-Dec-11 8:05am
v2
Comments
Sergey Alexandrovich Kryukov 16-Dec-11 15:03pm    
What's not working? Object.GetType is not working?! Do you really understand what do you need?
What is that "a instance object"?
--SA

1 solution

You're not using the method correctly. Type.GetType accepts the name of the type ypou want to get, so you should be doing it like this:

C#
Type myType = Type.GetType("System.String");


What I think you may be trying to do is this:

C#
Type myType = str.GetType();


EDIT (to answer your response) ==========================

You can't create an instance of a type.
 
Share this answer
 
v2
Comments
Wendelius 16-Dec-11 14:26pm    
From OP's solution:

Thanks for reply but it is not working for me.
I am getting result: {Name = "String" FullName = "System.String"}
and in next step:
object listObject = Activator.CreateInstance(myType);

Error:
No parameterless constructor defined for this object.

Thanks!
Kuldeep

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900