-6

Hi i have a Number of Properties and My properties like

public XYZ()
{
    xyz = new xyz1();
    xyz2 = new xyz2();
}
public xyz1 xyz1 { get; set; }
public xyz2 xyz2 { get; set; }
}

public class xyz1
{
    public string fName { get; set; }
    public string lnameget; set;}
}
public class xyz2
{
    public string city { get; set; }
    public string state
}

While i am setting my property on runtime i am getting exception object reference set to null.

XYZ model = new XYZ();
PropertyInfo propertyInfo = model.GetType().GetProperty("fName");
propertyInfo.SetValue(model, Convert.ChangeType(item.InnerText, propertyInfo.PropertyType), null);

Please help me

1 Answers1

0

model has no fName property, but model.xyz1 does.

GeoffreyGG
  • 11
  • 1
  • Yeah But i am getting exception while using this code -> PropertyInfo propertyInfo = model.GetType().GetProperty("fName"); propertyInfo.SetValue(model, Convert.ChangeType(item.InnerText, propertyInfo.PropertyType), null); – Vaibhav Srivastava Aug 16 '17 at 12:22