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 / .NET Framework / CLR / December 2005

Tip: Looking for answers? Try searching our database.

Assembly.LoadFrom and parameterized constructors

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Sempf - 05 Dec 2005 15:18 GMT
I want to instantiate a class at runtime that accepts a parameter, but I am
currently using Assembly.LoadFrom so I am having to do without the parameter.

Assembly.LoadFrom doesn't seems to support parameterized constructors (which
isn't a suprise, really) but it there another way I can accomplish the same
thing?

S
Dustin Campbell - 05 Dec 2005 15:57 GMT
> I want to instantiate a class at runtime that accepts a parameter,
> but I am currently using Assembly.LoadFrom so I am having to do
[quoted text clipped - 3 lines]
> (which isn't a suprise, really) but it there another way I can
> accomplish the same thing?

I'm a bit confused. Assembly.LoadFrom is for loading assemblies, not
instantiating types, correct? Why don't you use Assembly.LoadFrom to
load the assembly, Assembly.GetType() to find the type and then
Activator.CreateInstance() to create an instance of the type using the
correct constructor?

Signature

Best Regards,
Dustin Campbell
Developer Express, Inc

Morgan - 06 Dec 2005 02:08 GMT
Just to add to what Dustin is saying about the constructor, only offering
b/c I spent a couple of hours on this today ;)

In c# it would look something like this..
object[] objectargs = new object{"mystringparam", false, -1}
Activator.CreateInstance(myobjectstring, objectargs)

The parameters passed into the objectargs -must- match by position and type
those expected by the constructor. For example, as I learned today, passing
a StringBuilder to a string param yields a "Method not found" exception.
That's an hour of my life I'd sure like back ;).

--Morgan

>> I want to instantiate a class at runtime that accepts a parameter,
>> but I am currently using Assembly.LoadFrom so I am having to do
[quoted text clipped - 9 lines]
> Activator.CreateInstance() to create an instance of the type using the
> correct constructor?

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.