In the "Table" class, the "AddRow" method will occasionally throw a null reference exception because "this.rows" is null.
The following is the "AddRow" method and notice it references the internal property "rows" but it is null at times.
Code:
/// <summary>
/// Adds a new row to the table. Allowed only if at least one column was added.
/// </summary>
public Row AddRow()
{
return this.rows.AddRow();
}
The "getter" for "Rows" property in the "Table" class handles this by first checking for null and if not then it initializes it. The problem is that the method "AddRow" doesn't use the getter or checks for null first. Therefore, it throws an exception.
Code:
/// <summary>Gets the Rows collection of the table.</summary>
public Rows Rows
{
get
{
if (this.rows == null)
this.rows = new Rows((DocumentObject) this);
return this.rows;
}
set
{
this.SetParent((DocumentObject) value);
this.rows = value;
}
}
Shouldn't the method "AddRow" check for null first like the "getter"?
As a workaround all you have to do is access the "Rows" "getter" before making a call to "AddRow" and the problem is avoided because the "getter" initializes the value "rows". However, it would be nice to not have to think about doing that.