title: Reflection.TargetException problem
body: <p>I want the EmployeeNumber property for an Employee to only be set by the database, but I need to be able to set the value for unit testing. Which is why I made the helper code below.</p>
  
  <p>Can someone help me troubleshoot &amp; fix this?</p>
  
  <p>Cheers,<br>
  Berryl</p>
  
  <h1>Helper Code</h1>
  
  <pre><code>public static void SetEmployeeNumberFor(Employee employee, EmployeeNumber employeeNumber)
      {
          var empNumberProperty = employee.GetType().GetProperty("EmployeeNumber", BindingFlags.Public | BindingFlags.Instance);
  
          Check.Invariant(empNumberProperty != null);
          Check.Invariant(empNumberProperty.PropertyType.Equals(typeof(EmployeeNumber)));
  
          empNumberProperty.SetValue(empNumberProperty, employeeNumber, null);
      }
  </code></pre>
  
  <h1>Full Exception</h1>
  
  <pre><code>System.Reflection.TargetException : Object does not match target type.
  at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
  at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
  TestableEmployee.cs(36,0): at Smack.ConstructionAdmin.TestingSupport.ResourceHelper.SetEmployeeNumberFor(Employee employee, EmployeeNumber employeeNumber)
  TestableEmployee.cs(47,0): at Smack.ConstructionAdmin.TestingSupport.ResourceHelperTests.SetEmployeeNumberFor()
  </code></pre>
  
  <h1>EmployeeNumber property code</h1>
  
  <pre><code>    public virtual EmployeeNumber EmployeeNumber {
          get { return _employeeNumber; } 
          protected set {
              _employeeNumber = value;
              //base.BusinessId = _employeeNumber;
          }
      }
      private EmployeeNumber _employeeNumber;
  </code></pre>