Closed AntonVonDelta closed 7 months ago
I encountered the same issue. I had a different workaround by looping over all tables, their rows and cells and calling ResetCachedValues
using reflection.
I traced the issue to the DocumentObjectCollection.DeepCopy
where the parent is set after the clone. Therefore the cached values are calculated when the parent is not yet set and setting the parent does not trigger resetting the cached values.
One possible solution would be to call ResetCachedValues
in the setter of Parent
.
I had the same issue, and fixed it like @spl-sotax by modifying or adding ResetCachedValues method at:
In the case of Cell, I had to add a trick that is used in some other places in the Table getter to return table from Parent reference (Parent.Table) when _table is null.
In my case with those minor fixes the table rendering works like a charm.
Fixed with PDFsharp 6.1.0 Preview 3, release date not yet known, but coming soon. Thanks for your feedback.
Cloning a table doesn't properly set the parent of Cell objects. This leads to an NullReferenceException after calling
pdfRenderer.RenderDocument();
.My solution was to change the getters
Row
,Table
forCell.cs
andTable
forRow.cs
e.g:Expected Behavior
No exception thrown.
Actual Behavior
Exception thrown
"System.NullReferenceException: 'Object reference not set to an instance of an object.'"
atMigraDoc.DocumentObjectModel.Visitors.CellComparer.Compare(Cell cellLhs, Cell cellRhs)
on the lineint rowCmpr = cellLhs.Row.Index - cellRhs.Row.Index;
becausecellRhs.Row
is null.Steps to Reproduce the Behavior
Create a document, section and a table. Clone the table add it to the section. Render the document. An exception will be generated.