Search code examples
c#asp.netstrongly-typed-datasetactivatorcreateinstance

Define a typed dataset dynamically?


I am trying to create an instance of a typed dataset dynamically in my code at runtime. I have the type available to me, but when I try to do this:

object obj = Activator.CreateInstance(Type.GetType("TYPED DATASET TYPE HERE"));

The problem is the type doesn't seem to be valid according to the code when I try and run it. What could I be doing wrong here?


Solution

  • Where is the type defined? (which assembly).

    Unless you give it an assembly qualified name, it will only look in the calling assembly, and a few other key assemblies. Options:

    • use an assembly qualified name ("somen.amespace.sometype, someassembly, ...")
    • get the Assembly instance (from a known type in that assembly), and use GetType(fullyQualifiedName) on the Assembly instance