Re: Activating an instance of a class in a referenced assembly by Scott
Scott
Fri Feb 20 09:55:54 CST 2004
No, you are incorrect. The sample code I gave you, if run, will throw an
exception. If I take out the true parameter on the call to GetType I won't
get an exception, but the reference "importType" will be null.
And I can't do this statically, I need do do this dynamically with a string.
I need a way to dynamically instantiate an instance of a class that resides
in another assembly, and GetType() is not able to find it, it seems to only
work for classes in the same assemble as the caller.
"Wiktor Zychla" <user@nospam.com.eu> wrote in message
news:eVd8m369DHA.2532@TK2MSFTNGP09.phx.gbl...
> > For example, if you reference the System.Xml namespace, try this
> > Type importType = Type.GetType("System.Xml.XmlException", true);
>
> this is not the full type name. try:
>
> Type t = typeof( XmlException );
> MessageBox.Show( t.AssemblyQualifiedName );
>
> to see the full type name. you can use the full type name to get the type
by
> Type.GetType( "......." );
>
>
> remember that whenever the type is statically known, you can use
>
> Type t = typeof( _type_name_ );
> instead of
> Type t = Type.GetType( _fully_qualified_type_name );
>
> regards,
> Wiktor
>
>