Avatar of Chiliyago
ChiliyagoFlag for United States of America

asked on 

GetType().Assembly.CreateInstance("myUserContro") returns null

From my default.aspx pageI am trying to use reflection to create instances of user controls.  

I am using the latest version of .net and Visual Studio 2008.

When I call this line I always get a null result and I cannot understand why.

this.GetType().Assembly.CreateInstance("Controls_NameAddress",true)


Your help will be greatly appreciated.

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Chiliyago
Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

Is "Controls_NameAddress" the class that you are trying to instantiate?
Avatar of P_Ramprathap
P_Ramprathap
Flag of India image

Try with this
Assembly.GetAssembly(Controls_NameAddress).CreateInstance("Controls_NameAddress");
Note : instead of giving just Controls_NameAddress try with complete Namespace.classname
Another possibility is the class you are trying to instantiate is not found in the assembly. this.GetType().Assembly only refers to the assembly where the current object is declared, does not include other class libraries. A little correction to P_Ramprathap's suggestion:
Assembly.GetAssembly(typeof(Controls_NameAddress)).CreateInstance("Controls_NameAddress");
ASKER CERTIFIED SOLUTION
Avatar of P_Ramprathap
P_Ramprathap
Flag of India image

Blurred text
THIS SOLUTION IS 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
Avatar of Chiliyago
Chiliyago
Flag of United States of America image

ASKER

Thanks for everyone's help!
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo