3

I'm trying to create an instance of a class at run time. The classes I'm trying to create all inherit from a base class, ConfigMgrObj, and are named ConfigMgr_xxxxxx e.g. ConfigMgr_Collection. They all take a special object that I'm calling oController and a string as arguments.

This is the line I'm using to do it, where ClassToGet is a string that contains the name of the class e.g. ConfigMgr_Collection.

object oNewObject = System.Activator.CreateInstance(null, "StackOverflowNamespace." + ClassToGet, new object[] { oController, ClassToGet });

This throws a TypeLoadException exception. What's up with it?

1
  • Can you expand your question, is the assembly that contains the type loaded? Commented Oct 7, 2008 at 3:43

2 Answers 2

6

Are the types you're trying to instantiate actually declared within the same assembly? Passing null as the first parameter is telling Activator that the types live in the current assembly.

1
  • Dammit, that's it. I forgot I was doing this in the GUI, with all my stuff in the same namespace but a different assembly. Have an accepted answer to mitigate my stupidity.
    – Merus
    Commented Oct 7, 2008 at 3:55
0

Looks like it did not find the the class named "StackOverflowNamespace."+ClassToGet in the current assembly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.