I'm getting TargetInvocationException
in below code.
InnerException is "System.NullReferenceException".
I don't understand problem here. Can anyone tell me, where could be the problem?
C# code:
public class Harvest_Project
{
public string _name { get; set; }
private DateTime _over_budget_notified_at;
private bool _billable;
private DateTime _created_at;
private bool _active;
private enum _bill_by { Tasks, People, none };
public int _client_id;
private string _code;
private string _notes;
private enum _budget_by { project, project_cost, task, person, none };
private float _budget; //Budget in hrs
private DateTime _latest_record_at;
private DateTime _earliest_record_at;
private int _fees;
public int _id { get; set; }
private DateTime _updated_at;
private XmlNode _node;
public int getId() { return this._id; }
public Harvest_Project()
{ }
public Harvest_Project(XmlNode node)
{
this._node = node;
this._name = node.SelectSingleNode("name").InnerText;
this._created_at = Harvest_Base.storeTime(node.SelectSingleNode("created-at").InnerText);
this._updated_at = Harvest_Base.storeTime(node.SelectSingleNode("updated-at").InnerText);
this._over_budget_notified_at = Harvest_Base.storeTime(node.SelectSingleNode("over-budget-notified-at").InnerText);
this._latest_record_at = Harvest_Base.storeTime(node.SelectSingleNode("hint-latest-record-at").InnerText);
this._earliest_record_at = Harvest_Base.storeTime(node.SelectSingleNode("hint-earliest-record-at").InnerText);
this._billable = bool.Parse(node.SelectSingleNode("billable").InnerText);
try
{
this._id = Convert.ToInt32(node.SelectSingleNode("id").InnerText);
this._client_id = Convert.ToInt32(node.SelectSingleNode("client-id").InnerText);
this._budget = float.Parse(node.SelectSingleNode("budget").InnerText);
this._fees = Convert.ToInt32(node.SelectSingleNode("fees").InnerText);
}
catch (FormatException e)
{
Console.WriteLine("Input string is not a sequence of digits.");
}
catch (OverflowException e)
{
Console.WriteLine("The number cannot fit in an Int32.");
}
this._code = node.SelectSingleNode("code").InnerText;
this._notes = node.SelectSingleNode("notes").InnerText;
//TODO
//_this.bill_by
//this._budget_by
}
}
Exception is at line -
this._fees = Convert.ToInt32(node.SelectSingleNode("fees").InnerText);
Guess it's always neater to implement some sort of "TryGet" function to handle this kinda operation.