title: C# PropertyInfo GetValue() returns "Object does not match target type"
body: <p>I have a project that is reading rows returned from a SQL Server View, let's call the view 'Foo', and writing these rows to a series of files.  Using LINQ2SQL to reference the view in my project, results from  Foo are called 'FooResults'.</p>
  
  <p>The method provided below accepts the type of object to parse as well as the delimiter, the path to write the file to and a generic list of the data to be parsed. I've indicated where the exception is thrown.</p>
  
  <pre><code>public void WriteRecords&lt;T&gt;(T classType, string delimiter, string outputPath, List&lt;T&gt; data)
  {
      // Extract the property names and format as a delimited string
      var properties = classType.GetType().GetProperties().ToList();
      var headerLine = string.Join(delimiter, properties.Select(p =&gt; p.Name).ToArray());
      var formattedHeaderLine = new[] { headerLine };
  
      // Foreach line in the data provided, extract the values and format as delimited string
      foreach (var d in data)
      {
          try
          {
              foreach (var pinfo in d.GetType().GetProperties())
              {
                  // This is the line causing the problems
                  var value = pinfo.GetValue(pinfo, null);
              }
          }
          catch (Exception ex)
          {
              var message = ex.Message;
          }
      }
  }
  </code></pre>
  
  <p>The exception is:</p>
  
  <blockquote>
    <p>Object does not match target type</p>
  </blockquote>