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

Free Support Forum - aspose.com

LINQ Reporting with dynamic object using Aspose.Words for .NET

Hi

I am trying to create a document where the marked portion of the word will be replaced with property value. I am able to achieve this with concrete class. But in out scenario the class is dynamic. So I am trying the same with Expandoobject. But it is throwing an error.

System.InvalidOperationException: 'An error has been encountered at the end of expression ‘document.Name]>’. Can not get the value of member ‘Name’ on type 'Aspose.ExpandoWrapper

Here is my code. How can I acheive this dynamically.?

Document doc = new Document(dataDir + fileName);

        // Create a Reporting Engine.
        ReportingEngine engine = new ReportingEngine();
        var data = Common.GetManager();

        dynamic wrapper = new ExpandoWrapper(data); // convert class to dynamic object. 
        Console.WriteLine(wrapper.Name); // I have the data here
        // Execute the build report.
        engine.BuildReport(doc, wrapper, "document"); // error
        dataDir = dataDir + GetOutputFilePath(fileName);
        // Save the finished document to disk.
        doc.Save(dataDir);

@ann.sunny

Unfortunately, Aspose.Words does not support dynamic data sources in LINQ Reporting engine. However, we logged this feature request as WORDSNET-16017 in our issue tracking system. You will be notified via this forum thread once this feature is available. We apologize for your inconvenience.

Could you please attach the following resources here for testing:

  • Your input Word document.
  • 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.

We will investigate the issue and log it according to your requirement.

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

Hi Tahir,

It is not dynamic data source. I was checking about the data type ‘dynamic’ in C#.

Regards,
Balu

@ann.sunny

Please share the requested detail here for testing. We will investigate the issue and provide you more information on it.

@ann.sunny

In your case, we would like to suggest the following temporary workaround.

  1. Serialize the dynamic object to JSON using Newtonsoft.Json
  2. Initialize an instance of JsonDataSource using JSON achieved at the previous step
  3. Pass the JsonDataSource instance to the engine instead of the dynamic object

Hope this helps you.

Thank you. Let me try that.