On Apr 11, 8:40 am, Andrew <And...@discuss ions.microsoft. comwrote:
Okay, that means you've either not given the full classname (including
namespace) or it's not in mscorlib or the currently executing
assembly, in which case you need to give assembly details as well.
The line with testType2 is explicitly trying to find a class called
"name". The string "name" and the variable called name are completely
independent things.
That's natural - try compiling this:
Math m = new System.Math();
and you'll have the same kind of issue.
Well yes - you've failed to find the type, so Activator.Creat eInstance
can't possibly create an instance of it.
Is it in the same assembly as your calling code? If so, it's probably
just a case of putting the namespace on as well.
Jon
Hi,
>
I've looked at the Activator classes and I've come out with these samples of
code. However there is an error:
>
e.g. codes:
=======
string name = "ClassABC";
>
Type theMathType = Type.GetType("S ystem.Math");
Type testType = Type.GetType(na me);
Type testType2 = Type.GetType("n ame");
>
--both testType and testType2 gives "null".
>
I've looked at the Activator classes and I've come out with these samples of
code. However there is an error:
>
e.g. codes:
=======
string name = "ClassABC";
>
Type theMathType = Type.GetType("S ystem.Math");
Type testType = Type.GetType(na me);
Type testType2 = Type.GetType("n ame");
>
--both testType and testType2 gives "null".
namespace) or it's not in mscorlib or the currently executing
assembly, in which case you need to give assembly details as well.
The line with testType2 is explicitly trying to find a class called
"name". The string "name" and the variable called name are completely
independent things.
Object theObj2 = Activator.Creat eInstance(theMa thType); --Error: Cannot
create an abstract class.
create an abstract class.
Math m = new System.Math();
and you'll have the same kind of issue.
Object theObj3 = Activator.Creat eInstance(testT ype); --Error: Value
cannot be
null. Parameter name: type.
Object theObj4 = Activator.Creat eInstance(testT ype2); --Error: Value
cannot be
null. Parameter name: type.
cannot be
null. Parameter name: type.
Object theObj4 = Activator.Creat eInstance(testT ype2); --Error: Value
cannot be
null. Parameter name: type.
can't possibly create an instance of it.
I'm not very familiar with CreateInstance method etc ...
I just want to create an instance of "name" which is the name of the class
that I want to instantiate.
I just want to create an instance of "name" which is the name of the class
that I want to instantiate.
just a case of putting the namespace on as well.
Jon