title: Parameter Count Mismatch exception when calling PropertyInfo.GetValue
body: <p>I'm trying to compare two objects at runtime using reflection to loop through their properties using the following method:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub CompareObjects(obj1 As Object, obj2 As Object)
  
      Dim objType1 As Type = obj1.GetType()
  
      Dim propertyInfo = objType1.GetProperties
  
      For Each prop As PropertyInfo In propertyInfo
          If prop.GetValue(obj1).Equals(prop.GetValue(obj2)) Then
              'Log difference here
          End If
      Next
  End Sub
  </code></pre>
  
  <p>Whenever I test this method, I'm getting a Parameter Count Mismatch exception from System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck when it calls prop.GetValue(obj1). </p>
  
  <p>This happens no matter the type of obj1 and obj2, nor the type in prop (in my test case, the first property is a Boolean).</p>
  
  <p>What am I doing wrong and how can I fix it so that I can compare the values from the two objects?</p>
  
  <p><strong>Solution</strong></p>
  
  <p>I added the following lines just inside the for each loop:</p>
  
  <pre><code>Dim paramInfo = prop.GetIndexParameters
  If paramInfo.Count &gt; 0 Then Continue For
  </code></pre>
  
  <p>The first property was taking a parameter, which was causing the problem. For now, I'll just skip any property that requires a parameter.</p>