Activator.CreateInstance error [modified]
-
I am trying to create a class that is NOT abstract but is inherited from an abstract class. When trying to create this class using Activator.CreateInstance, I get an error saying: "Cannot create an abstract class". However, I am not tyring to create an instance of an abstract class rather a class that can be instanciated and is not abstract. See code below... Any ideas? Thanks in advance.
namespace Test
{
[Serializable]
public abstract class Cls1
{
...
public static Cls1 Open()
{
Cls1 provider = null;
string typeName = "Test.Cls3";
Type t = Type.GetType(typeName);
provider = Activator.CreateInstance(t) as Cls1; // <----------- Error Here
}
}[Serializable]
public abstract class Cls2 : Cls1
{
...
}[Serializable]
public sealed class Cls3 : Cls2
{
...
}
}-- Modified Wednesday, April 7, 2010 3:08 PM
-
I am trying to create a class that is NOT abstract but is inherited from an abstract class. When trying to create this class using Activator.CreateInstance, I get an error saying: "Cannot create an abstract class". However, I am not tyring to create an instance of an abstract class rather a class that can be instanciated and is not abstract. See code below... Any ideas? Thanks in advance.
namespace Test
{
[Serializable]
public abstract class Cls1
{
...
public static Cls1 Open()
{
Cls1 provider = null;
string typeName = "Test.Cls3";
Type t = Type.GetType(typeName);
provider = Activator.CreateInstance(t) as Cls1; // <----------- Error Here
}
}[Serializable]
public abstract class Cls2 : Cls1
{
...
}[Serializable]
public sealed class Cls3 : Cls2
{
...
}
}-- Modified Wednesday, April 7, 2010 3:08 PM