question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AspNetCore 3.0 Exception: "Cache entry must specify a value for Size when SizeLimit is set."

See original GitHub issue

Is AspNetCore 3.0 supported? I’m getting this exception on page load. Is this a bug or config error? It worked previously.

Packages:

MiniProfiler.AspNetCore.Mvc ------- 4.1.0 MiniProfiler.EntityFrameworkCore – 4.1.0

Services Call:

services.AddMiniProfiler().AddEntityFramework();

Configure Call:

app.UseMiniProfiler();

StackTrace:

System.InvalidOperationException: Cache entry must specify a value for Size when SizeLimit is set. Module “Microsoft.Extensions.Caching.Memory.MemoryCache”, in SetEntry Module “Microsoft.Extensions.Caching.Memory.CacheEntry”, in Dispose Module “Microsoft.Extensions.Caching.Memory.CacheExtensions”, in Set File “C:\projects\dotnet\src\MiniProfiler.AspNetCore\Storage\MemoryCacheStorage.cs”, line 160, col 13, in Save File “C:\projects\dotnet\src\MiniProfiler.AspNetCore\Storage\MemoryCacheStorage.cs”, line 195, col 13, in SaveAsync File “C:\projects\dotnet\src\MiniProfiler.Shared\ProfileProviders\DefaultProfilerProvider.cs”, line 112, col 13, in SaveAsync Module “System.Runtime.ExceptionServices.ExceptionDispatchInfo”, in Throw Module “System.Runtime.CompilerServices.TaskAwaiter”, in ThrowForNonSuccess Module “System.Runtime.CompilerServices.TaskAwaiter”, in HandleNonSuccessAndDebuggerNotification Module “System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter”, in GetResult File “C:\projects\dotnet\src\MiniProfiler.Shared\ProfileProviders\DefaultProfilerProvider.cs”, line 78, col 13, in StoppedAsync Module “System.Runtime.ExceptionServices.ExceptionDispatchInfo”, in Throw Module “System.Runtime.CompilerServices.TaskAwaiter”, in ThrowForNonSuccess Module “System.Runtime.CompilerServices.TaskAwaiter”, in HandleNonSuccessAndDebuggerNotification Module “System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter”, in GetResult File “C:\projects\dotnet\src\MiniProfiler.Shared\MiniProfiler.cs”, line 243, col 13, in StopAsync Module “System.Runtime.ExceptionServices.ExceptionDispatchInfo”, in Throw Module “System.Runtime.CompilerServices.TaskAwaiter”, in ThrowForNonSuccess Module “System.Runtime.CompilerServices.TaskAwaiter”, in HandleNonSuccessAndDebuggerNotification Module “System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter”, in GetResult File “C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs”, line 112, col 17, in Invoke Module “System.Runtime.ExceptionServices.ExceptionDispatchInfo”, in Throw Module “System.Runtime.CompilerServices.TaskAwaiter”, in ThrowForNonSuccess Module “System.Runtime.CompilerServices.TaskAwaiter”, in HandleNonSuccessAndDebuggerNotification Module “System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter”, in GetResult

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Cooksaucecommented, Oct 28, 2019

@NickCraver

Looks like EF Core is setting up the SizeLimit on line 258: https://github.com/aspnet/EntityFrameworkCore/blob/release/3.0/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs

TryAdd<IMemoryCache>(p => new MemoryCache(new MemoryCacheOptions { SizeLimit = 10240 }));

Work-Around: I was able to get it working by setting up the IMemoryCache manually before the EF Core registration:

services.AddMemoryCache();

services
     .AddEntityFrameworkNpgsql()
     .AddDbContext<MyDbContext>(
          options => options
               .UseNpgsql(connectionString, o => o.SetPostgresVersion(9, 6))
               .UseLazyLoadingProxies(),
          ServiceLifetime.Transient,
          ServiceLifetime.Transient);

services.AddMiniProfiler().AddEntityFramework();

Permanent Solution: Do you have any suggestions on getting MiniProfiler to play nice with a MemoryCache that has the MemoryCache.SizeLimit set?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cache entry must specify a value for Size when SizeLimit is ...
Unexpected "Cache entry must specify a value for Size when SizeLimit is set" message in AspNetCore 3. So this all worked fine before...
Read more >
Cache in-memory in ASP.NET Core
SizeLimit doesn't have units. Cached entries must specify size in whatever units they consider most appropriate if the cache size limit has been ......
Read more >
In-Memory Caching in ASP.NET Core
While using a MemoryCache instance, there is an option to specify a size limit. The cache size limit does not have a defined...
Read more >
Simple C# MemoryCache implementation – Understand the ...
Each cache entry you insert must specify a size (integer). The MemoryCache will then hold entries until that limit is met. Example: I...
Read more >
In Memory Caching on .NET 6.0 - Nishān Wickramarathna
If the cache size limit is set, all entries must specify size. The ASP.NET Core runtime doesn't limit cache size based on memory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found