Hi,Okay, that means you've either not given the full classname (including
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: CannotThat's natural - try compiling this:
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: ValueWell yes - you've failed to find the type, so Activator.Creat eInstance
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 ...Is it in the same assembly as your calling code? If so, it's probably
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