We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

When Array is Empty, even the <<if [arrayName.Any()]>> is false, still failed on evaluating item.attribute

With the latest Aspose.Words for .NET 20.6,
Let’s use the example here

You have chosen <<if [!items.Any()]>>no items<><<[items.Count()]>> item(s)<>.

If I changed to this one, assume items = []
(ignore extra spaces)

<<if [items.Any()]>>
<<foreach [item in items]>><<[item.attributeName]>><< /foreach >>
<< else >>
no items
<< /if >>

it will fail with this error
System.InvalidOperationException: ‘An error has been encountered at the end of expression ‘item.attributeName]>’. Can not get the value of member ‘attributeName’ on type ‘System.Data.DataRow’.’

It looks that, even the array is empty, the report engine still goes to do the evaluation of attribute name first.
Thanks for any help.

Regards,
Zhenyu

@zhenyu.wang,

Please ZIP and attach the following resources here for testing:

  • Your simplified template Word document
  • A standalone simple console application (source code without compilation errors) that helps us to reproduce this System.InvalidOperationException on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size

As soon as you get these pieces of information ready, we will start investigation into your particular scenario and provide you more information.

ConsoleApp3.zip (358.7 KB)

Hi Hafeez,

I have uploaded the .zip file.
Input word document ‘test.docx’ is in \bin\Debug folder

Regards,
Zhenyu

@zhenyu.wang,

We managed to observe the following error upon running the code you shared.

System.InvalidOperationException
  HResult=0x80131509
  Message=An error has been encountered at the end of expression 'ActivityLocation.LocationName]>'. Can not get the value of member 'LocationName' on type 'System.Data.DataRow'.
  Source=Aspose.Words

For the sake of any correction, we have logged this problem in our issue tracking system with ID WORDSNET-20653. We will further look into the details of this problem and will keep you updated on the status of the linked issue. We apologize for your inconvenience.

@zhenyu.wang,

Regarding WORDSNET-20653, it is to update you that we have completed the analysis of this issue and concluded to close this issue with “Not a Bug” status. Please see the following analysis details:

This is an expected behavior. The LINQ reporting engine needs to analyze data source members used in a template in order to perform certain operations. Since member ‘attributeName’ is missing in the data source, the exception is thrown. To work around this, we have the ReportBuildOptions.AllowMissingMembers option that is intended to be used in scenarios exactly like this one. Please check the following section of documentation for more information.

Hi @awais.hafeez
Thank you for quick reply and the solution.:grinning:

Regards,
Zhenyu