Getting "Unexpected subdocument type exception"

Hi,

I’m getting the following error:

System.InvalidOperationException occurred
Message=Unexpected subdocument type.
Source=Aspose.Words
StackTrace:
at xa604c4d210ae0581.x93b05c1ad709a695.x7625b7f02c65c1cd(x9e131021ba70185c x77b06614416ee4d3)
at x9e260ffa1ac41ffa.x8b8ab0cf32b35f3c.x4d04bff8a4c56cac(ShapeBase x5770cdefd8931aa9)
at x9e260ffa1ac41ffa.x8b8ab0cf32b35f3c.x7ab5ac84420414e0(ShapeBase x5770cdefd8931aa9)
at x9e260ffa1ac41ffa.x8b8ab0cf32b35f3c.x84e71ff4edf2ec72(ShapeBase x5770cdefd8931aa9)
at x9e260ffa1ac41ffa.x8b8ab0cf32b35f3c.x1a2622a1866b8f97(ShapeBase x5770cdefd8931aa9)
at x9e260ffa1ac41ffa.x8b8ab0cf32b35f3c.x1f70c910ab814928(Shape x5770cdefd8931aa9)
at x9e260ffa1ac41ffa.x163859bfa28558c4.VisitShapeStart(Shape shape)
at Aspose.Words.Drawing.Shape.x2449520719b1e37e(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Drawing.Shape.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Paragraph.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Tables.Cell.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Tables.Row.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Tables.Table.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Drawing.Shape.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Paragraph.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Body.Accept(DocumentVisitor visitor)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x51ee56decc29a9da(Section xb32f8dd719a105db)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x160a0bf4de8f6bd0()
at x9e260ffa1ac41ffa.x163859bfa28558c4.x8cac5adfe79bc025(x8556eed81191af11 x5ac1382edb7bf2c2)
at Aspose.Words.Document.xf381a641001e6830(Stream xcf18e5243f8d5fd3, String xafe2f3653ee64ebc, SaveOptions xc27f01f21f67608c)
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)
at Aspose.Words.Document.Save(Stream stream, SaveFormat saveFormat)
at SHL.DocumentEngine.Implementations.AsposeWords.AsposeWordsSerialiser.Save(MemoryStream& stream) in C:\Code\SHL.ReportEngine.DocumentEngine\Implementations\AsposeWords\AsposeWordsSerialiser.cs:line 55
InnerException: 

I’m getting it when I try to Create a document with a paragraph which has a shape and the shape has a table with 9 rows and 9 cells in each row. There are also images in the cells. I’m getting the error once I’ve created the aspose document and I’m calling save.

I had seen the bug fix list for 10.3 and I had thought it was fixed but I’m running 10.4 and it’s still not working.

Kind Regards,

Gavin

Hello

Thanks for your inquiry. Could you please attach your code here for testing? I will check the problem on my side and provide you more information.

Best regards,

Hi Andrey,

It took me a while to get back to this problem but here is the code I am calling to create the aspose table based on a data model provided. I’ve added context based comments to make it easier to understand.

// Create aspose table

this.AsposeTable = new Aspose.Words.Tables.Table(this.Aspose.Document);

// Add the table rows into the table. This in turn adds the cell for each table.
// When adding the cells images and nested tables are/can be added.
// For my test i know images and a nested table is added.

TableRowSerialiser serialiser = null;
foreach(ITableRow row in this.Table.Rows)
{
    serialiser = new TableRowSerialiser(this, row);
    this.AsposeTable.Rows.Add(serialiser.Serialise());
}

// Place the table into a text box.
// We need this because I need to be able to potentially put two tables next to each other.

if (this.Table.IsConvertToImage)
{
    AsposeWordsDrawing.Shape shape = new AsposeWordsDrawing.Shape(this.Aspose.Document,
        AsposeWordsDrawing.ShapeType.TextBox);
    shape.AppendChild(this.AsposeTable);

    Aspose.Words.Paragraph paragraph = new Aspose.Words.Paragraph(this.Aspose.Document);
    paragraph.AppendChild(shape);

    // Return the text box to the calling code if the convert to image option is selected.

    return paragraph;
}

// Return the table.

return this.AsposeTable;

Please note the above code works but if fails when i try to save it.

Here is the code I use.

MemoryStream stream = new MemoryStream();
this.Aspose.Document.Save(stream, SaveFormat.Doc);

Hope this is enough information.

Hi
Thank you for additional infornation. You can use code like the following to insert Table into textbox:

Document doc = new Document();
// Create table.
Table table = new Table(doc);
for (int rowIndex = 0; rowIndex <9; rowIndex++)
{
    Row row = new Row(doc);
    row.RowFormat.Height = 30;
    table.Rows.Add(row);
    // Create the cells for the row
    for (int cellIndex = 0; cellIndex <9; cellIndex++)
    {
        Cell cell = new Cell(doc);
        cell.CellFormat.Borders.LineWidth = 1;
        cell.CellFormat.Borders.Color = System.Drawing.Color.Black;
        cell.CellFormat.Width = 30;
        row.Cells.Add(cell);
    }
}
// Create a shape for table.
Shape tableBox = new Shape(doc, ShapeType.TextBox);
// Configure text box.
tableBox.Width = 154;
tableBox.Height = 154;
tableBox.Stroked = false;
tableBox.TextBox.FitShapeToText = true;
// Insert a table into a text box.
tableBox.AppendChild(table);
// Insert text box into the document.
doc.FirstSection.Body.FirstParagraph.AppendChild(tableBox);
// Save output.
doc.Save("C:\\Temp\\out.doc");

Hope this helps.
Best regards,