PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Nov 20, 2019 3:41 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Feb 05, 2019 6:17 pm 
Offline

Joined: Tue Feb 05, 2019 5:49 pm
Posts: 1
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 05, 2019 7:47 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 503
Location: CCAA
Hi!
blake.causey wrote:
However, it would be nice to not have to think about doing that.
I've been using MigraDoc for years and I never had this exception.

Thanks for your feedback. We'll include that fix in future versions of MigraDoc.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group