title: How to use a superclass method using reflections C#
body: <p>I have a bunch of classes that inherit from a single class. I'm using reflections to access the classes, since the ones that will be accessed will change in runtime.</p>
  
  <p>But I am having some trouble when trying to invoke a method declared at superclass.</p>
  
  <p>Here is my parent class:</p>
  
  <pre><code>public class ParentClass {
  
      public ParentClass (Type type) {
  
      }
  
      public string method0String () {
          return string;
      }
  
      public void method1Void (string) {
  
      }
  
  }
  </code></pre>
  
  <p>Here is my child class:</p>
  
  <pre><code>public class ChildClass : ParentClass {
  
      public ParentClass () : base(typeof(ChildClass)) {
  
      }
  
  }
  </code></pre>
  
  <p>Here is the abstract class code where I cast the methods:</p>
  
  <pre><code>Type childType = Type.GetType(className[i]);
  ConstructorInfo childConstructor = childType.GetConstructor(new Type[0]);
  
  object childObject = null;
  childObject = childConstructor.Invoke(childObject, new object[0]);
  
  MethodInfo parentMethod0String = childType.GetMethod("method0String");
  MethodInfo parentMethod1Void = childType.GetMethod("method1Void");
  
  parentMethod1Void.Invoke(childObject, new object[]{argString});
  object finalString = parentMethod0String.Invoke(childObject, new object[0]);
  </code></pre>
  
  <p>The MethodInfos are always null, which causes this error when I try to invoke them:</p>
  
  <pre><code>System.NullReferenceException: Object reference not set to an instance of an object
  </code></pre>
  
  <p>I haven't found anyway around this.</p>
  
  <p>Basically, I just need to invoke a super method using the child as the dynamic object. How can I achieve this?</p>
  
  <p>@Edit</p>
  
  <p>After @nvoigt answer, my code looks like this:</p>
  
  <pre><code>Type childType = Type.GetType(className[i]);
  object childObject = Activator.CreateInstance(childType);
  
  Type parentType = Type.GetType("ParentClass");
  MethodInfo parentMethod0String = parentType.GetMethod("method0String");
  MethodInfo parentMethod1Void = parentType.GetMethod("method1Void");
  
  parentMethod1Void.Invoke(childObject, new object[]{argString});
  object finalString = parentMethod0String.Invoke(childObject, new object[0]);
  </code></pre>
  
  <p>And the error is a little different:</p>
  
  <pre><code>System.Reflection.TargetException: Object does not match target type.
  </code></pre>