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

Free Support Forum - aspose.com

LINQ Reporting engline throws System.InvalidOperationException using C#

Hi,
I have used foreach tag in word template to iterate list of objects,
Current Scenario: I am creating dynamic class at run time that class can have properties like List SWSolution {get; set;} where SWSolution is a class, now if i get empty list in response like {SWSolution: []}, then i will not be able to create a class as i will not be having any properties for that, so i am setting property type as List SWSolutoin and set its value to empty list,

dynamically created class will look like this:

Public class DynamicClass {
public List SWSolution {get; set;}
}

When i pass this object of dynamic class to our engine as
engine.BuildReport(document, dynamicClassInstance, “tableList”);

it gives me error saying:
“Message”: “An error has occurred.”,
“ExceptionMessage”: “An error has been encountered at the end of expression '(a. PurchaseOption”’. Can not get the value of member ‘PurchaseOption’ on type ‘System.Object’.",
“ExceptionType”: “System.InvalidOperationException”,

here how i am accessing SWSolution in my template :
image.png (6.2 KB)

Even if condition applied on table is false it check for SWSolution properties.
How can we avoid to access properties when List is empty?
Please do some needful.

I found similar query, here is the link Can not iterate over an instance of type ‘System.Object’. ’

@Chandresh015

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

A post was split to a new topic: How can we avoid to access properties when List is empty?