The problem is the CreateInstance. It needs the full type name, which
includes the namespace. If this
Dim a as [Assembly] = [Assembly].GetExecutingAssembly()
wasn't working you'd get a null reference exception on this line
CurrentObject = a.CreateInstance(NodeObjectName)
because "a" would be null
What
Dim a as [Assembly] = [Assembly].GetExecutingAssembly()
does, is two things, which might clearer if you wrote it like this
Dim a as [Assembly] 'dimension an Assembly object
a = [Assembly].GetExecutingAssembly() 'set a = the currently
executing assembly, ie the running application
(and yes, you need the brackets, Assembly is also a keyword so you
need the brackets to tell the compiler you want to work the the
Assembly class)
To make
CurrentObject = a.CreateInstance(NodeObjectName)
work, you need to add the namespace
CurrentObject = a.CreateInstance("Ninocentral.Apps.Infomanager." &
NodeObjectName)
If it can't find the type, it just returns a null reference (it
doesn't throw an exception).
On 10/27/05, Matías Niño ListMail <[EMAIL PROTECTED]> wrote:
>
> Thanks for the help Dean. All the objects I'm trying to instancies all
> implement a standard interface.
>
> Unfortunately, I can't seem to instantiate the object successully. The
> CreateInstance method runs without error, but the CurrentObject remains
> uninstantiated and null. I get a
>
> Here's my exact code from the ASPX page:
>
> 'get data row
> Dim CurrentRowID as Integer = 1 ' Test value for Row ID
> Dim NodeObjectName as String = "LinkNode" ' Text value for object type
> name
>
> 'Instantiate Node object and render
> Dim a as [Assembly] = [Assembly].GetExecutingAssembly()
> Dim CurrentObject
> CurrentObject = a.CreateInstance(NodeObjectName)
> response.write(CurrentObject.Render(CurrentRowID))
>
>
> I think my problem is that I don't understand what Dim a as [Assembly] =
> [Assembly].GetExecutingAssembly() actually does.
>
> Am I supposed to leave the brackets in there?
>
> Here's some info that might help:
> My assembly's name is called Ninocentral. It resides in the bin directory
> (not the GAC) and its namespace is imported into the current page.
> The object I'm trying to instantiate is in the following namespace:
> Ninocentral.Apps.Infomanager
>
> Thanks again,
>
> M.
>
>
>
>
>
>
> ________________________________
From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Dean
Fiala
> Sent: Thursday, October 27, 2005 1:05 PM
> To: [email protected]
> Subject: Re: [AspNetAnyQuestionIsOk] OOP Help?
>
>
> Assuming all the objects inherit from a common base class or implement
> the same interface, you could do something like this...
>
> Dim a as Assembly = [Assembly].GetExecutingAssembly()
> Dim CurrentObject as iRow
>
> For Each iRow in dtObjects.rows
> CurrentObject = a.CreateInstance(ObjectType)
> CurrentObject.Render()
> Next
>
> On 10/27/05, Matías Niño ListMail <[EMAIL PROTECTED]> wrote:
> > This question if for anyone with a good understanding of how OOP works in
> > .NET.
> >
> > I have an ASP.NET web page with a bunch of rows in a Datatable.
> >
> > Each row contains a string column (ObjectType) which represents one of
> > many class types.
> >
> > I need .NET to be able to instantiate the object specified by that string
> > column and call a common RENDER() method that all the objects will have.
> >
> > What I'm trying to avoid doing is coding a giant select statement that
> > translates the objecttype string and instantiates the right object. I'd
> > Imagine .NET can somehow do that. Am I right?
> >
> > Here's pseudocode of what I'm imagining must be possible:
> >
> > For Each iRow in dtObjects.rows
> > Dim CurrentObject as New iRow("ObjectType")
> > CurrentObject.Render()
> > Next
> >
> > Thanks in advance for any pointers.
> >
> > M.
> > Manassas, VA
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
> --
> Dean Fiala
> Very Practical Software, Inc
> http://www.vpsw.com
>
>
>
> SPONSORED LINKS
> Basic programming language Computer programming
> languages Programming languages
> Java programming language
>
> ________________________________
YAHOO! GROUPS LINKS
>
>
> Visit your group "AspNetAnyQuestionIsOk" on the web.
>
> To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
> ________________________________
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/