Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

ConstructorInfo

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JimHeavey - 17 Jul 2007 22:52 GMT
I'm trying to figure out how to use the ConstructorInfo class to get the
appropriate constructor and then use the "Invoke" method to create and
instance of the class.  Seems easy enough, but it is not working for me, so
it must be something simple.

Here is the code that I am using, and the last instruction fails.
    Type[] parms = { typeof(NullableDataReader) };
    Type theTblType = Type.GetType(_TableClassName);
    ConstructorInfo methodCreate = theTblType.GetConstructor(parms);
    object rec = methodCreate.Invoke(theTblType, argumentItems);
When the last instruction executes, I get a "TargetException" - Object does
not meet the target type.
When I look at the "theTblType", it shows me "{Name = "PS_GL_ACCOUNT_TBL"
FullName = "GL.Table.PS_GL_ACCOUNT_TBL"}  and this the class that I am
attempting to create.  Below is the constructor for that class, which takes
as an arguement  NullableDataReader, which is what I believe I am passing
into the Invoke method.  
Here is the constructor of the class that I am trying to create an instance
of..

       public PS_GL_ACCOUNT_TBL(NullableDataReader row)

What Am I doing wrong?

Second question, the Invoke method returns an "object", but how can I "cast"
this to a "PS_GL_ACCOUNT_TBL" type when all I have is the text name of that
class?

Thanks in advance for your assistance!!
Kevin Spencer - 18 Jul 2007 12:33 GMT
You're passing a variable called "argumentItems" to the Invoke method, but
you haven't described what that is.

Signature

HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

> I'm trying to figure out how to use the ConstructorInfo class to get the
> appropriate constructor and then use the "Invoke" method to create and
[quoted text clipped - 31 lines]
>
> Thanks in advance for your assistance!!
JimHeavey - 18 Jul 2007 14:16 GMT
I seemed to have missed posting that code, but it is indeed populated.  I
have created another post, where I expand the code in the post, but the
results are the same.

Thanks for taking the time to post your comments!!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.