title: Assembly Invoking using ConstructorInfo with Reflection
body: <p>I've looked through the other posts and have not found anything that specifically hits on this issue, so here we go...</p>
  <p>I have an external DLL class...</p>
  <pre><code>namespace Utility
  {
      //o--------------------------------o
      //| string style Enumerator class  |
      //o--------------------------------o
      public class StringEnumerator : IEnumerable&lt;string&gt;
      {
          protected List&lt;string&gt; _elements;
  
          //our constructor
          public StringEnumerator(string[] array)
          {
              this._elements = new List&lt;string&gt;(array);
          }
  
          IEnumerator&lt;string&gt; IEnumerable&lt;string&gt;.GetEnumerator()
          {
              return this._elements.GetEnumerator();
          }
  
          IEnumerator IEnumerable.GetEnumerator()
          {
              return this._elements.GetEnumerator();
          }
      }
  }
  </code></pre>
  <p>In my testing application I can get the constructor but I can't invoke it...</p>
  <pre><code>            Type tmpType2 = localCore.GetType(&quot;Utility.StringEnumerator&quot;, false, true);
              object ot2a = Activator.CreateInstance(tmpType2, null);
              // Prove that we an object.
              DisplayBuffer($&quot;A {ot2a.GetType().Name} object has been created&quot;);
              foreach (MethodInfo mi in tmpType2.GetMethods())
              {
                  DisplayBuffer($&quot;  Utility.StringEnumerator.MethodInfo.Name: {mi.Name}&quot;);
              }
              Type[] conTypes = { typeof(string[]) };
              // Get a reference to the correct constructor.
              ConstructorInfo ci2 = tmpType2.GetConstructor(conTypes);
              DisplayBuffer($&quot;Utility.StringEnumerator.ConstructorInfo.Name: {ci2.Name}&quot;);
              
              // Prepare the parameters.
              object[] args4 = { &quot;Help&quot;, &quot;me&quot;, &quot;please&quot; };
  
              // Invoke the constructor and assign the result to a variable. 
              object o4 = ci2.Invoke(args4); //&lt;-- This causes an error
              DisplayBuffer($&quot;Invoked: {o4}&quot;);
  </code></pre>
  <p>The error I get is: System.Reflection.TargetParameterCountException: 'Parameter count mismatch.'</p>
  <p>If I try this...</p>
  <pre><code>object o4 = ci2.Invoke(new object[] { &quot;test string to pass&quot; });
  </code></pre>
  <p>I get the error: System.ArgumentException: 'Object of type 'System.String' cannot be converted to type 'System.String[]'.'</p>
  <p>Thanks to Peter for the help... this was the solution:</p>
  <pre><code>string[] args4 = { &quot;test&quot;, &quot;array&quot;, &quot;of&quot;, &quot;strings&quot; };
  object o4 = ci2.Invoke(new object[] { args4 });
  </code></pre>