title: Parameter count mismatch when getting value of property using Reflection
body: <p>I am getting a <em>Parameter Count mismatch</em> error which I don't understand.</p>
  
  <p>I have the below code:</p>
  
  <pre><code>Type target = Type.GetType("CPS_Service." + DocumentType);
  
  // Create an instance of my target class
  instance = Activator.CreateInstance(target);
  
  foreach (XElement pQ in PQData.Elements())
  {
      try
      {
      // populate the member in the instance of the data class with the value from the MQ String
          if (target.GetProperty(pQ.Attribute("name").Value) != null)
          {
              target.GetProperty(pQ.Attribute("name").Value).SetValue(instance, pqRequest[Convert.ToInt32(pQ.Attribute("pos").Value)], null);
          }
      }
  }
  
  PropertyInfo[] properties = target.GetProperties();
  
  foreach (PropertyInfo property in properties)
  {
      DataColumn col = new DataColumn(property.Name);
      col.DataType = System.Type.GetType("System.String");
      col.DefaultValue = "";
      dt.Columns.Add(col);
  }
  
  DataRow dr = dt.NewRow();
  
  foreach (PropertyInfo property in properties)
  {
      string value = property.GetValue(instance).ToString();
      dr[property.Name.ToString()] = "";
  }
  dt.Rows.Add(dr);
  
  return dt; //
  </code></pre>
  
  <p>so I am instantiating a generic class and populating it from a string array (taken from a tab-delimited string), then I need to either output a List or a datatable from the class <code>instance</code></p>
  
  <p>When populating the datarow <code>dr</code> for my datatable <code>dt</code> I am trying to get the value from the class:</p>
  
  <pre><code>string value = property.GetValue(instance, null).ToString();
  dr[property.Name.ToString()] = "";
  </code></pre>
  
  <p>but on the line <code>property.GetValue(instance).ToString();</code> I get the below error:</p>
  
  <blockquote>
    <p>Parameter count mismatch</p>
  </blockquote>
  
  <p>I have searched around and the other questions about this error do not apply...</p>
  
  <p>Or would I be better off just casting my class to a List and returning that?</p>