User function not found in report after unpacking trdp document

1 Answer 207 Views
.NET 5 Report Book Report Designer (standalone)
Oleg
Top achievements
Rank 1
Iron
Oleg asked on 28 Dec 2022, 06:02 AM

Hello,

I've created a report in standalone report designer with custom function. And saved it in trdp format.

I added a custom function and connected the assembly as described in this manual.

In the report editor, I see my function and use it, however when I try to use this report for printing, my function becomes unavailable.

public class BaseReportBook<TModel> : ReportBook, IDisposable
{
    public virtual byte[] CreatePdf(TModel model, ReportTypeEnum reportType)
    {
        var reportPackager = new ReportPackager();
        using var sourceStream = File.OpenRead(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports", reportType.GetDescription()));
        var report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);

        report.ItemDataBinding += new EventHandler((sender, e) => Report_ItemDataBinding(sender, e, model));
        InstanceReportSource reportSource = new InstanceReportSource();
        reportSource.ReportDocument = report;
        ReportSources.Add(reportSource);

        ReportProcessor reportProcessor = new ReportProcessor();
        var instanceReport = new InstanceReportSource();
        instanceReport.ReportDocument = this;
        RenderingResult result = reportProcessor.RenderReport("PDF", instanceReport, null);

        if (result.Errors.Length > 0)
            throw new Exception(string.Join("\r\nError: ", result.Errors.Select(s => s.Message)));
        return result.DocumentBytes;
    }

    private void Report_ItemDataBinding(object sender, EventArgs e, TModel model)
    {
        Telerik.Reporting.Processing.Report item = (Telerik.Reporting.Processing.Report)sender;
        item.DataSource = model;
    }

    protected override void Dispose(bool disposing)
    {
        base.Dispose(disposing);
        GC.SuppressFinalize(this);
        GC.Collect();
    }
}
reportType.GetDescription() returns the name of the report (e.g. test.trdp)

 

The report is successfully generated, but it does not see my function. Although they are in the same assembly.


When viewing the preview in the editor, the function works:

 

Here is the function itself:

public static class CustomFunctions
{
    [Function(Category = "Images", Namespace = "Extension", Description = "Images")]
    public static Image GetLogo() => new Bitmap(Properties.Resources.logo);
}


1 Answer, 1 is accepted

Sort by
1
Accepted
Dimitar
Telerik team
answered on 29 Dec 2022, 03:22 PM

Hello Oleg,

Thank you for the provided information!

User Functions behave like the ObjectDataSource component, they are resolved, at runtime, using the configuration of the running application.

This essentially means that in order to use the custom functions in the project that renders the report to PDFs, that project's configuration file should also have to use the Telerik Reporting assemblyReferences Element. For example:

"telerikReporting": {
    "assemblyReferences": [
        {
            "name": "MyUserFunctionsAssembly",
            "version": "1.0.0.0",
            "culture": "neutral",
            "publicKeyToken": "null"
        }
    ]
}

This should be added to the appsettings.json configuration file of the project that executes the CreatePdf method.

For more details on this topic, you may have a look at Configuration for the Report Viewer/Web Report Designer.

Please let me know if you have any further questions.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Oleg
Top achievements
Rank 1
Iron
commented on 03 Jan 2023, 12:29 PM

It works! Thank you very much for your answer!
Tags
.NET 5 Report Book Report Designer (standalone)
Asked by
Oleg
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Share this question
or