title: C# Reflection - Object does not match target type
body: <p>I'm trying to use the <code>propertyInfo.SetValue()</code> method to set an object property value with reflection, and I'm getting the exception "Object does not match target type".  It doesn't really make sense (at least to me!) as I'm just trying to set a simple string property on an object with a string replacement value.  Here's a code snippet - this is contained within a recursive function so there's a bunch more code, but this is the guts:</p>
  
  <pre><code>PropertyInfo fieldPropertyInfo = businessObject.GetType().GetProperties().FirstOrDefault(f =&gt; f.Name.ToLower() == piecesLeft[0].ToLower());
  businessObject = fieldPropertyInfo.GetValue(businessObject, null);
  
  fieldPropertyInfo.SetValue(businessObject, replacementValue, null);
  </code></pre>
  
  <p>I've verified that <code>businessObject" and</code>replacementValue` are both the same type by doing this comparison, which returned true:</p>
  
  <pre><code>businessObject.GetType() == replacementValue.GetType()
  </code></pre>