Telerik reporting user functions

1 Answer 15 Views
.NET Core Expressions Programming Report Viewer - HTML5 Rest Service
NSP
Top achievements
Rank 1
NSP asked on 02 Apr 2025, 09:29 AM

Hello. Can somebody please help me with custom user functions.

I am using Kendo reporting version 2025 Q1 (19.0.25.211) in my Net Core 8 project. I am using dynamically created reports (not from any template or similar).

Here is the code behind all with config and everything.

Config in app.config xml file:

In my Startup.cs in ConfigureServices I am calling this extension method:
services.AddTelerikReporting();

Here is the extension method:

Here is my custom report resolver:

Here is my custom user function:

I am using it when creating report xml like this:

private static void SetCategoryDateFormat(QueryResult resultDataModel, int dateIndex, GraphGroup categoryGroup, string dateFormat)
{
    var value = "NSP.NSPDateFormat(" + StringFormatHelper.RemoveDotsAndCommaAndSpace(resultDataModel.Columns[dateIndex].PropertyPath) + ", '" + dateFormat + "')";
    categoryGroup.Groupings.Add(new Grouping("=" + value));
}

I can confirm that in xml I receive from my rest api, in my custom report source resolver I get that in my xml string representing report definition which I than deserialize. 

The report is ok, but the call to this custom user function gives me this error:

The expression contains object 'NSP' that is not defined in the current context.

The resolver and custom user function are all in the same assembly NSP.Web.

Also here is the code in razor page for hmlt5 report viewer:

Can anybody give me an idea on why this error, what is happening? 

I have wasted a lot of time trying this to work?

Please don't hesitate to ask further questions.

Thanks in advance.

 

 

 

 

NSP
Top achievements
Rank 1
commented on 03 Apr 2025, 10:12 AM

I tried moving config from xml to appsettings.json, but still no solution. Still the same error.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Apr 2025, 02:50 PM

Hello,

Thank you for the shared code and the additional information!

For the user functions to be resolvable by the reporting service, the assembly with those functions should be registered in the assemblyReferences Element and the configuration with this element should be made into a configuration object that implements the IConfiguration interface. This object should be provided to the service through the ReportingEngineConfiguration property of the ReportServiceConfiguration.

I see that you were previously using custom code to provide the configuration to the ReportingEngineConfiguration property from .config files. Since this is a .NET application, I would recommend using a .JSON configuration file, at least for the configuration provided to the reporting service, as it should be easier to load.

I saw your comment as well, that you tried configuring the settings in the appsettings.json file but did you create an IConfiguration object of this JSON configuration and did you provide it to the ReportingEngineConfiguration property? For example:

// Configure dependencies for ReportsController.
services.TryAddSingleton<IReportServiceConfiguration>(sp =>
    new ReportServiceConfiguration
    {
        ReportingEngineConfiguration = ResolveSpecificReportingConfiguration(sp.GetService<IWebHostEnvironment>()),
        HostAppId = "Net6RestServiceWithCors",
        Storage = new FileStorage(),
        ReportSourceResolver = new TypeReportSourceResolver()
            .AddFallbackResolver(
                new UriReportSourceResolver(reportsPath))
    });
static IConfiguration ResolveSpecificReportingConfiguration(IWebHostEnvironment environment)
{
    // If a specific configuration needs to be passed to the reporting engine, add it through a new IConfiguration instance.
    var reportingConfigFileName = Path.Combine(environment.ContentRootPath, "reportingAppSettings.json");
    return new ConfigurationBuilder()
        .AddJsonFile(reportingConfigFileName, true)
        .Build();
}

Below is a sample JSON with configuration for white-listing an assembly used in the reports:

"telerikReporting": {
    "assemblyReferences": [
        {
            "name": "MyUserFunctionsAssembly"
        }
    ]
}

In case the issue persists after providing the configuration as suggested above, please send me a runnable project where the issue is reproducible so that I can debug it locally and make sure that the function is correctly written in the report with regards to the namespace and the name of the used method.

I hope that the provided information will help resolve the issue and look forward to receiving an update from you.

Regards,
Dimitar
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Tags
.NET Core Expressions Programming Report Viewer - HTML5 Rest Service
Asked by
NSP
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or