ReportingEngine.BuildReport throws System.InvalidOperationException using .NET

Hi,

I am new Aspose Words user.

I have a Holder.ABN and Holder.ACN two string fields.
How to do the check, if both are empty string, then output ‘N/A’

I tried this, but it is not working.
<<if [Holder.ABN != “”] && [Holder.ACN != “”] >>
N/A
<< / if>>
(I have added extra space here to make close if tag visible in forum)

There are two issues:

  1. ‘&&’ is not supported?
  2. ABN could be a number, then it cannot compare with “”.

Thanks for help in advance

Regards,
Zhenyu

@zhenyu.wang

We suggest you please read the following articles.
Using Operators
Using Conditional Blocks

In case you are using old version of Aspose.Words, we suggest you please upgrade to the latest version of Aspose.Words for .NET 20.2.

If you still face problem, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • 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.

@tahir.manzoor

Hi Tahir,
ConsoleApp2.zip (4.9 MB)

I have upload a zip file, with

  • input word document ‘test.docx’ in \bin\Debug folder
  • output word, nothing because throw error ''An error has been encountered at the end of expression ‘Holder.ABN != “”] ‘. Can not apply operator ‘!=’ to operands of type ‘System.Nullable`1[System.Int32]’ and ‘System.String’.’’
  • expected output word, if no error, then the output is what I want
  • standalone console application, included in the .zip

@zhenyu.wang

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-19979. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi @tahir.manzoor
Just follow up, it there any update on this issue?

@zhenyu.wang

We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

@zhenyu.wang

Please use the latest version of Aspose.Words for .NET 20.6 and set JsonDataLoadOptions.SimpleValueParseMode to JsonSimpleValueParseMode.Strict as shown below to get the desired output.

private static void GenerateAsposeDocument(string templateName, string jsonPayload)
{
    var doc = new Document(templateName);
             
    JsonDataLoadOptions options = new JsonDataLoadOptions();
    options.SimpleValueParseMode = JsonSimpleValueParseMode.Strict;

    var dataStream = new MemoryStream(Encoding.ASCII.GetBytes(jsonPayload));
    var jsonDataSource = new JsonDataSource(dataStream, options);

    var engine = new ReportingEngine();
    engine.BuildReport(doc, jsonDataSource);

    // Save the finished document to disk.
    doc.Save(MyDir + "20.6.docx");
}

Hi Tahir,

I have tried with the latest v20.6 and the ParseMode as you said.

But it still does not work.
The current error is
'An error has been encountered at the end of expression 'Holder.ABN != “”] ‘. Can not apply operator ‘!=’ to operands of type ‘System.Nullable`1[System.Int32]’ and ‘System.String’.’

Could you please have a try first?

Regards,
Zhenyu

@zhenyu.wang

This issue has been fixed using following code snippet. Please make sure that you are using Aspose.Words for .NET 20.6.

JsonDataLoadOptions options = new JsonDataLoadOptions();
options.SimpleValueParseMode = JsonSimpleValueParseMode.Strict;

However, the issue related to && operator is not fixed. We logged separate issue for it as WORDSNET-20594. We apologize for your inconvenience.

Hi Tahir,

Thank for quick reply.
I can confirm the compare with “” is working now.

The missing code snippet is this one
var jsonDataSource = new JsonDataSource(dataStream, options);

Regards,
Zhenyu

@zhenyu.wang

Can you please confirm if && operator works at your end?

<<if [Holder.ABN != “”] && [Holder.ACN != “”] >>
N/A
<</if>>

Hi Tahir,

No, it is NOT working.
Error message is
‘Tag ‘if’ is not well-formed. Character ‘&’ is unexpected.’

Regards,
Zhenyu

@zhenyu.wang

We will inform you via this forum thread once this issue is resolved.

The issues you have found earlier (filed as WORDSNET-19979) have been fixed in this Aspose.Words for .NET 20.6 update and this Aspose.Words for Java 20.6 update.

@zhenyu.wang

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-20594) as ‘Not a Bug’.

Please use the following 'if' tag syntax to get the desired output. We have attached the modified input document with this post for your kind reference. LinqTest.zip (9.3 KB)

<<if [Holder.ABN != "" && Holder.ACN != ""] >>
N/A
<</if>>