ReportProcessor - Error handling for field mismatch

2 posts, 0 answers
  1. Casper
    Casper avatar
    11 posts
    Member since:
    May 2019

    Posted 30 Jul 2019 Link to this post


    When generating a PDF report using the ReportProcessor from a trdx report,
    is it possible to catch errors such as if a used field in the template is
    not present in the dataset?

    I'm using the ErrorEventHandler like this, but it is not triggered if a used field is not present in dataset.
    It just renders the report anyway and leaves the label empty.

    reportObject.Error += (innerSender, eventArgs) =>
        _logger.Error(eventArgs.Exception, "Error processing report PDF", reportId, parameters);

    If you don't support it today, it would be great if I could decide, whether or not the processor should trigger the error handler in cases like this.


  2. Ivan Hristov
    Ivan Hristov avatar
    214 posts

    Posted 01 Aug 2019 Link to this post

    Hello Casper,

    Such scenario is supported by the reporting engine. If an expression uses a field that is not present in the dataset, the relevant item throws an exception with the message "The expression contains object 'object-name-here' that is not defined in the current context.". This error bubbles up to the error handler of the ReportProcessor and is reflected in Errors property of the RenderingResult object, returned by the ReportProcessor, as the following code demonstrates:

    var rs = new InstanceReportSource() { ReportDocument = new Dashboard() };
    var processor = new Telerik.Reporting.Processing.ReportProcessor();
    processor.Error += ((s, e) =>
    var result = processor.RenderReport("PDF", rs, null);
    if (result.HasErrors)
        Debug.WriteLine(string.Join("; ", result.Errors.Select(e => e.Message)));

    To test it, I used our example Dashboard report and changed the expression of the spLabelSalesPerson text box from =Fields.SalesPersonFullName to =Fields.SalesPersonFullName1, which clearly does not exist in the datasource. When the code above is run, the Debug console will contain the string: The expression contains object 'SalesPersonFullName1' that is not defined in the current context., repeated couple of times, because the textbox is evaluated a couple of times.

    If your scenario differs from the one above, please give us more details about it so we can investigate it on our side.

    Ivan Hristov
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top