LINQ Reporting Engine - Headers created in a foreach loop causes an error with predefined table of contents

Hi everyone,

this one may be something obvious but I didn’t find something in the forum nor in the docs.
I am dynamically generating headings using the template syntax.

3 TOPIC DETAILS
<<foreach [topic in auditTopics.Rows]>>
3.1 TOPIC <<[ TOPIC != null ? TOPIC[“WFD_ATTTEXT1”] :“”] >>: <<[ TOPIC != null ? TOPIC[“WFD_ATTTEXT1GLOB”] : “”] >>

This works fine, as long as there’s no table of content.
As soon as I add one, the template syntax is part of the ToC and the document generation fails with an error:
Without ?: condition
An error has been encountered at the end of expression ‘topic["’. Can not get the value of member ‘topic’ on type ‘System.Collections.Generic.Dictionary`2[System.String,System.Data.DataTable]’.

With ?: condition
An error has been encountered at the end of expression ’ topic != '. Can not get the value of member ‘topic’ on type ‘System.Collections.Generic.Dictionary`2[System.String,System.Data.DataTable]’.

image.png (18.4 KB)

I used the ?: condition in the hope I could work around it, as I didn’t expect to “topic” to have a value at all, as the ToC is on the first page and the the foreach on the third.

Does anyone have an idea?

Best regards,
Daniel

@Daniel_Krueger
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25823

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

I have used the following simple template and code to reproduce the problem:

Document doc = new Document(@"C:\Temp\\in.docx");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, new string[] { "topic1", "topic2", "topic3" }, "topics");

doc.Save(@"C:\Temp\out.docx");

as a workaround you can modify the code like this:

Document doc = new Document(@"C:\Temp\\in.docx");

ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.AllowMissingMembers;
engine.BuildReport(doc, new string[] { "topic1", "topic2", "topic3" }, "topics");

doc.UpdateFields(); // Required to update the TOC
doc.Save(@"C:\Temp\out.docx");

in.docx (14.4 KB)

Thank you very much for your fast response and the work around. :slight_smile:

I will forward it internally.

1 Like

@Daniel_Krueger

It is to let you know that after Aspose.Words 23.11 is released, you will be able to use ReportBuildOptions.UpdateFieldsSyntaxAware to update fields in a template-syntax-aware manner while building a report as follows:

ReportingEngine engine = new ReportingEngine();
engine.Options |= ReportBuildOptions.UpdateFieldsSyntaxAware;
engine.BuildReport(...);

Note that enabling of the option makes the engine to update fields while building a report, so there is no need to update fields separately after that.

The issues you have found earlier (filed as WORDSNET-25823) have been fixed in this Aspose.Words for .NET 23.11 update also available on NuGet.