I have two C# classes that have many of the same properties (by name and type). I want to be able to copy all non-null values from an instance of Defect into a
Defect
Replace your erroneous line with this:
PropertyInfo targetProperty = defectViewModel.GetType().GetProperty(defectProperty.Name); targetProperty.SetValue(viewModel, defectValue, null);
Your posted code is attempting to set a Defect-tied property on a DefectViewModel object.
DefectViewModel