I am just re-referencing to an earlier post as I could not quite get the issue resolved. C# convert string to class that has a constructor with string parameter
I have a loop in which I am trying to convert given strings into class types and instantiate them. Those classes have constructors with a string type parameter, which is a connection string to a database.
Up to this point seems OK. ExampleClass1, ExampleClass2, ExampleClass3...
Type type = Type.GetType("ExampleClass1");
object instance = Activator.CreateInstance(type, "connection_string_param");
However, when I try to access the class methods via the instance.DoSomething() I receive an error - object does not contain a definition for DoSomething.... When I instantiate the class regular way, I can see the class methods. Arturo Menchaca was suggesting to cast, appreciate his help earlier on, but casting the 'object' type into 'specific class type' would not work if the class type is not known yet. If I try (type)instance, it does not work... Any help is appreciated.