I am working on aspose.words and getting below issue
Can not apply operator ‘&&’ to operands of type ‘System.Nullable`1[System.Boolean]’ and ‘System.Boolean’
Same issue is for String and Integer for using && and != operator
Below is code I am using:
ReportingEngine reportingEngine = new ReportingEngine();
JsonDataSource documentJsonData = new JsonDataSource(myData);
reportingEngine.BuildReport(templateDocument, documentJsonData);
templateDocument.Save(generatedDocument, PDF);
@ggarg904 You have not provided your template document and data. Without these details, the only thing I can say is about the exception message itself: It literally says that the &&
operator cannot be applied to operands of type bool?
and bool
. If you try to use the &&
operator with operands of these types in plain C#, the compiler will raise a similar compile-time error. Since LINQ Reporting Engine uses a subset of C# language in its syntax, using of operators in template expressions should follow the same restrictions imposed by C#. All in all, this is an expected behavior rather than a bug. By the same reason, &&
and !=
operators cannot be applied to operands of types string
and int
.
Please find document attached.
Below is the JSON DATA:
{
"JDEOrderDetails": {
"Header": {
"TotalAmount": 0.00
}
}
}
Below is the error we getting:
“An error has been encountered at the end of expression 'totalistrue= head.TotalAmount!=null && head.TotalAmount!=”"]>’. Can not apply operator ‘!=’ to operands of type ‘System.Nullable`1[System.Int64]’ and ‘System.String’."
Just for reference purpose my issue is same as below issue:
https://forum.aspose.com/t/linq-reporting-engine-nullable-int-is-not-recognized-for-jsondatasource-using-net/213191
As per the above document it got fixed in 20.6
But I am using 23.1.0 version of aspose.words but still same issue
Please help us ASAP. As we are blocked on it to finalize for the Aspose.words
@ggarg904
As I have already shared, the error raised by LINQ Reporting Engine literally says what is wrong. In this case, you try to apply the !=
operator to operands of type long?
(TotalAmount
is a number as per your JSON data) and string
(an empty string as per your template), which does not work as it is prohibited in pure C# and the engine implements the same behavior. This is an expected behavior rather than a bug. I have modified your template to make it work by applying the !=
operator to numeric operands. Please check OrderDetailsTest_Modified.docx
As a note, you can check validity of your expressions in pure C# before using them in a template.