HTML5 Report Viewer stops working when IDistributedCache is implemented

0 Answers 60 Views
.NET Core Report Viewer - HTML5
Steve
Top achievements
Rank 1
Steve asked on 03 Jul 2023, 05:00 AM | edited on 03 Jul 2023, 08:43 PM

My report viewer was working without issue for some time until caching with DistributedSqlServerCache was implemented. It is configured as follows.

services.TryAddSingleton<IReportServiceConfiguration>(configuration =>
    new ReportServiceConfiguration {
        HostAppId = "Reports",
        ReportingEngineConfiguration = new ConfigurationBuilder().AddJsonFile(Path.Combine(configuration.GetService<IWebHostEnvironment>().ContentRootPath, "appsettings.json"), true).Build(),
        ReportSourceResolver = new UriReportSourceResolver(Path.Combine(configuration.GetService<IWebHostEnvironment>().ContentRootPath, "App_Data")).AddFallbackResolver(new TypeReportSourceResolver()),
        Storage = new MsSqlServerStorage("connection-string")
    }
);
public class ReportsController : ReportsControllerBase {
    public ReportsController(IReportServiceConfiguration reportServiceConfiguration) : base(reportServiceConfiguration) {
        reportServiceConfiguration.Storage.AcquireLock(string.Format("Lock-{0}", new Random().Next()));
    }
}

Note that the AcquireLock() method mentioned above was added in response to this comment from Telerik:

The interface also exposes a method called AcquireLock which is used from the service to enforce serialized access to all stored resources from each thread of the application and between the instances of the application in case of multi-instance environment (i.e., Web Farm)

Which I suspect may apply here, but unfortunately I can only hazard guess in light of its appalling lack of documentation.

A typical error message reported by the viewer is:

Error creating report document (Report = 'XXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Format = 'HTML5'). An error has occurred. Object reference not set to an instance of an object.

As a workaround, I have resorted to manually configuring the report viewer, then editing a method in the javascript file, from this:
function registerDocumentAsync(format, deviceInfo, useCache, baseDocumentId, actionId) {
    throwIfNotInitialized();
    throwIfNoReportInstance();

    return client.createReportDocument(clientId, reportInstanceId, format, deviceInfo, useCache, baseDocumentId, actionId).catch(function(xhrErrorData) {
        handleRequestError(xhrErrorData, utils.stringFormat(sr.errorCreatingReportDocument, [ utils.escapeHtml(report), utils.escapeHtml(format) ]));
    });
}

to this:

function registerDocumentAsync(format, deviceInfo, useCache, baseDocumentId, actionId) {
    throwIfNotInitialized();
    throwIfNoReportInstance();

    return client.createReportDocument(clientId, reportInstanceId, format, deviceInfo, useCache, baseDocumentId, actionId).catch(function () {
        console.log("Failed to create report document. A retry has been attempted.");

        return client.createReportDocument(clientId, reportInstanceId, format, deviceInfo, useCache, baseDocumentId, actionId).catch(function (xhrErrorData) {
            handleRequestError(xhrErrorData, utils.stringFormat(sr.errorCreatingReportDocument, [utils.escapeHtml(report), utils.escapeHtml(format)]));
        });
    });
}
Up until now, the second attempt has worked every time. The odd thing is, after the workaround is applied it can continue to work for some time without failing again, even after loading a different page. Given that I cannot reproduce this issue locally, I suspect there may be a race condition happening.
Dimitar
Telerik team
commented on 05 Jul 2023, 02:03 PM

Hi Steve,

We are not aware of there being any issues with the SqlServerCache and IDistributedCache.

The "Error creating report document (Report = 'XXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Format = 'HTML5'). An error has occurred. Object reference not set to an instance of an object." message suggests that the Resolve Document request is failing but the last part - "Object reference not set to an instance of an object" is too ambiguous to draw any conclusions from it.

In order to get more information about the error, please produce and share in this ticket the following logs:

Even better, if possible, attach a sample project where the issue is reproducible so that we may debug it locally.

I will be looking forward to receiving an update from you.

Steve
Top achievements
Rank 1
commented on 05 Jul 2023, 09:49 PM

Hi Dimitar

The trace option resulted in the error:

IOException: The process cannot access the file 'D:\home\site\wwwroot\log.txt' because it is being used by another process.

I ran Fiddler Jam and have a link that I don't want to post here. How can I share it with you privately?

Dimitar
Telerik team
commented on 10 Jul 2023, 03:20 PM

Hi Steve,

I opened a new support ticket so that you may share the logs there.

No answers yet. Maybe you can help?

Tags
.NET Core Report Viewer - HTML5
Asked by
Steve
Top achievements
Rank 1
Share this question
or