LinQ Engine - Exception "Can not get the value of member..."

Now I am testing the LinQ Report Engine, we use the following code:

final Document doc = new Document("AsposeLinqTable.docx");
ReportingEngine.setUseReflectionOptimization(false);
final ReportingEngine engine = new ReportingEngine();
ArrayList<Contract> contracts = Common.getContracts();
engine.buildReport(doc, contracts, "Contracts");
doc.save("LinqTableResult.docx");

The Common class is direct from Aspose Example Repository: https://github.com/aspose-words/Aspose.Words-for-Java/blob/master/Examples/DocsExamples/Java/src/main/java/DocsExamples/LINQ_Reporting_Engine/Helpers/Common.java

And here is the test file: AsposeLinqTable.docx (13 KB)

We use Aspose Words Evaluation Edition.

However, we get such a StackTrace:

Exception in thread "main" java.lang.IllegalStateException: An error has been encountered at the end of expression 'Contract c '. Keyword 'in' is expected.
	at com.aspose.words.internal.zzYm8.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzYm8.zzZd9(Unknown Source)
	at com.aspose.words.internal.zzZfb.zzZtK(Unknown Source)
	at com.aspose.words.internal.zzYbm.zzVPc(Unknown Source)
	at com.aspose.words.internal.zzYbm.zzZvB(Unknown Source)
	at com.aspose.words.internal.zzYbm.zzWcD(Unknown Source)
	at com.aspose.words.internal.zzYbm.zzZ69(Unknown Source)
	at com.aspose.words.internal.zzZfb.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzZfb.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzW9h.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzW9h.zzXSa(Unknown Source)
	at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
	at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
	at de.forcont.documentconverter.docx4j.service.AsposeConverter.tableFillingTest(AsposeConverter.java:395)

@zwei In your template you have explicitly specify iteration variable type. This type must be known by the engine. Please try using the following code:

final Document doc = new Document("C:\\Temp\\AsposeLinqTable.docx");
ReportingEngine.setUseReflectionOptimization(false);
final ReportingEngine engine = new ReportingEngine();
List<Contract> contracts = Common.getContracts();
engine.getKnownTypes().add(Contract.class);
engine.buildReport(doc, contracts, "Contracts");
doc.save("C:\\Temp\\out.docx");

Thanks, after add following instruction

engine.getKnownTypes().add(Contract.class);

New Exception comes:

Exception in thread "main" java.lang.IllegalStateException: An error has been encountered at the end of expression 'Contracts.Sum(c => c.getPrice())]'. Can not resolve method 'getPrice' on type 'class java.lang.Object'.
	at com.aspose.words.internal.zzYm8.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzYm8.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzZfb.zzZir(Unknown Source)
	at com.aspose.words.internal.zzYbm.zzXdh(Unknown Source)
	at com.aspose.words.internal.zzYbm.zzWcD(Unknown Source)
	at com.aspose.words.internal.zzYbm.zzZ69(Unknown Source)
	at com.aspose.words.internal.zzZfb.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzZfb.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzW9h.zzXSa(Unknown Source)
	at com.aspose.words.internal.zzW9h.zzXSa(Unknown Source)
	at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
	at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
	at de.forcont.documentconverter.docx4j.service.AsposeConverter.tableFillingTest(AsposeConverter.java:396)
	at de.forcont.documentconverter.docx4j.Docx4JTestMain.main(Docx4JTestMain.java:27)

This time we test another docx file: AsposeLinqTable.net.docx (12,9 KB)

@zwei In your case you should use a variable to calculate sum in foreach block and then use the value of this variable. For example see the attached modified template:
AsposeLinqTable_modified.docx (13.4 KB)

In the original template c variable is out of foreach scope.

1 Like

Thank you very much, Спасибо!

1 Like