Cache entry must specify a value for Size when SizeLimit is set.

Stimulsoft Reports.NET discussion
Post Reply
Evokati
Posts: 5
Joined: Mon Sep 23, 2024 8:39 am

Cache entry must specify a value for Size when SizeLimit is set.

Post by Evokati »

So, I have a .net 6 MVC project. And I need to replace DevExpress reports with Stimulsoft.

I added package Stimulsoft.Reports.Web.NetCore
Added a DesignerController:

Code: Select all

public class DesignerController : Controller
{
	public IActionResult Index()
	{
		return View("StiDesigner");
	}

	public IActionResult GetReport()
	{
		var report = new StiReport();
		report.Load(StiNetCoreHelper.MapPath(this, "Reports/MyTwoSimpleLists.mrt"));

		return StiNetCoreDesigner.GetReportResult(this, report);
	}

	public IActionResult DesignerEvent()
	{
		return StiNetCoreDesigner.DesignerEventResult(this);
	}
}
Then added a view:

Code: Select all

@using Stimulsoft.Report.Mvc

@{
    ViewBag.Title = "StiDesigner";   
}


@Html.StiNetCoreDesigner(new StiNetCoreDesignerOptions()
{
    Actions =
    {
        GetReport = "GetReport",
        DesignerEvent = "DesignerEvent"
    }
}) 
When I try to open that view I see an error in the browser console:
https://localhost:44364/Designer/Design ... nerScripts net::ERR_ABORTED 500 (Internal Server Error)

The error is thrown on this line:
return StiNetCoreDesigner.DesignerEventResult(this);
inside DesingerController

The whole call stack:

Code: Select all

System.InvalidOperationException
  HResult=0x80131509
  Message=Cache entry must specify a value for Size when SizeLimit is set.
  Source=Microsoft.Extensions.Caching.Memory
  StackTrace:
   at Microsoft.Extensions.Caching.Memory.MemoryCache.SetEntry(CacheEntry entry)
   at Microsoft.Extensions.Caching.Memory.CacheEntry.Dispose()
   at Microsoft.Extensions.Caching.Memory.CacheExtensions.Set[TItem](IMemoryCache cache, Object key, TItem value, MemoryCacheEntryOptions options)
   at Stimulsoft.System.Web.Caching.Cache.Add(String key, Object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
   at Stimulsoft.Report.Web.StiCacheHelper.SaveObject(Object obj, String guid)
   at Stimulsoft.Report.Web.StiDesignerResourcesHelper.GetScripts(StiRequestParams requestParams) in Stimulsoft.Report.Web\StiDesignerResourcesHelper.cs:line 210
   at Stimulsoft.Report.Web.StiDesignerResourcesHelper.Get(StiRequestParams requestParams) in Stimulsoft.Report.Web\StiDesignerResourcesHelper.cs:line 99
   at Stimulsoft.Report.Mvc.StiNetCoreDesigner.DesignerEventResult(StiRequestParams requestParams, StiReport report) in Stimulsoft.Report.Mvc\StiNetCoreDesigner.cs:line 554
   at ContractsRegistry.Controllers.DesignerController.DesignerEvent() in D:\Work\Contracts Registry\Source\ContractsRegistry\Controllers\DesignerController.cs:line 23
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) in /_/src/Mvc/Mvc.Core/src/Infrastructure/ActionMethodExecutor.cs:line 83
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() in /_/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs:line 395
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) in /_/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs:line 250
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() in /_/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs:line 303

  This exception was originally thrown at this call stack:
    Microsoft.Extensions.Caching.Memory.MemoryCache.SetEntry(Microsoft.Extensions.Caching.Memory.CacheEntry)
    Microsoft.Extensions.Caching.Memory.CacheEntry.Dispose()
    Microsoft.Extensions.Caching.Memory.CacheExtensions.Set<TItem>(Microsoft.Extensions.Caching.Memory.IMemoryCache, object, TItem, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions)
    Stimulsoft.System.Web.Caching.Cache.Add(string, object, Stimulsoft.System.Web.Caching.CacheDependency, System.DateTime, System.TimeSpan, Stimulsoft.System.Web.Caching.CacheItemPriority, Stimulsoft.System.Web.Caching.CacheItemRemovedCallback)
    Stimulsoft.Report.Web.StiCacheHelper.SaveObject(object, string)
    Stimulsoft.Report.Web.StiDesignerResourcesHelper.GetScripts(Stimulsoft.Report.Web.StiRequestParams) in StiDesignerResourcesHelper.cs
    Stimulsoft.Report.Web.StiDesignerResourcesHelper.Get(Stimulsoft.Report.Web.StiRequestParams) in StiDesignerResourcesHelper.cs
    Stimulsoft.Report.Mvc.StiNetCoreDesigner.DesignerEventResult(Stimulsoft.Report.Web.StiRequestParams, Stimulsoft.Report.StiReport) in StiNetCoreDesigner.cs
    ContractsRegistry.Controllers.DesignerController.DesignerEvent() in DesignerController.cs
    Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultTypeMapper, Microsoft.Extensions.Internal.ObjectMethodExecutor, object, object[]) in ActionMethodExecutor.cs
When I try to do the same inside a new project everything works fine. So, I guess there is something inside my project that causes that. It's pretty old (was originally written in .net framework then migrated to .net 6).
But I have no idea where to look? I'd appreciate any help.
Lech Kulikowski
Posts: 7287
Joined: Tue Mar 20, 2018 5:34 am

Re: Cache entry must specify a value for Size when SizeLimit is set.

Post by Lech Kulikowski »

Hello,

Please send us the project configuration (ConfigureServices method), and other similar information on project configuration.
This error means that your project has a cache size limit set somewhere, it should be removed for correct functioning.
or another option is to use a session for caching reports (Server.CacheMode property of the viewer).

Thank you.
Evokati
Posts: 5
Joined: Mon Sep 23, 2024 8:39 am

Re: Cache entry must specify a value for Size when SizeLimit is set.

Post by Evokati »

Hm. I have no idea where a cache size limit is set.
This is my ConfigureServices:

Code: Select all

public void ConfigureServices(IServiceCollection services)
{
	services.AddDevExpressControls();

	services.AddEntityFrameworkNpgsql().
		AddDbContext<ApplicationDbContext>(options =>
			options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"))
		);

    services.AddDatabaseDeveloperPageExceptionFilter();


    services.AddIdentity<ApplicationUser, IdentityRole>(options => 
    { 
        options.SignIn.RequireConfirmedAccount = false;
        options.Password.RequireDigit = false;
        options.Password.RequireLowercase = false;
        options.Password.RequireUppercase = false;
        options.Password.RequireNonAlphanumeric = false;
        options.Password.RequiredUniqueChars = 0;                
    })
        .AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();


	services.Configure<DataProtectionTokenProviderOptions>(opt => opt.TokenLifespan = TimeSpan.FromDays(7));

	services.AddAuthorization(options =>
    {
        options.FallbackPolicy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .Build();
    });

	services.AddAuthentication(options =>
	{
		options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
	})
	.AddCookie();

	services.AddRazorPages();
	services.ConfigureApplicationCookie(options => { 
		options.LoginPath = "/Accounts/Login";
		options.AccessDeniedPath = "/Home/AccessDenied";
	});

	services.AddControllersWithViews()
		.AddNewtonsoftJson(options =>
		options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore).AddRazorRuntimeCompilation();

	
	services.ConfigureReportingServices(configurator => {					
		configurator.ConfigureWebDocumentViewer(viewerConfigurator => {
			viewerConfigurator.UseCachedReportSourceBuilder();
		});
	});

	services.AddAutoMapper(typeof(Startup));

	services.AddTransient<DbSeeder>();		
	services.AddHttpClient<ExternalAuthService>();
	services.AddScoped<RolesService>();
	services.AddScoped<ITnoesRepository, TnoesRepository>();
	services.AddSingleton<IScopedDbContextProvider<ApplicationDbContext>, ScopedDbContextProvider<ApplicationDbContext>>();
	services.AddSingleton<OperationsStatusesService>();
	services.AddTransient<IApiKeyValidation, ApiKeyValidation>();
	services.AddScoped<ApiKeyAuthFilter>();
	services.AddScoped<SvodReportService>();			

	services.AddHttpContextAccessor();
}
I experimented a little bit and it seems that adding
services.AddMemoryCache();
at the start of ConfigureServices solved the problem.
Lech Kulikowski
Posts: 7287
Joined: Tue Mar 20, 2018 5:34 am

Re: Cache entry must specify a value for Size when SizeLimit is set.

Post by Lech Kulikowski »

Hello,

Thank you for sharing your information.
Post Reply